Skip to content

'str' object has no attribute 'get()' #836

@eshanholtz

Description

@eshanholtz

Issue Summary

When sending a message that contains a Ganalytics member of a TrackingSettings object, sg.send() makes calls to .get() to build the associated JSON data. This results in a .get() call being made on the Ganalytics members, some of which are the primitive str type and do not have the .get() method. The line causing the error can be found here.

Steps to Reproduce

  1. run temp.py:
# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
from sendgrid.helpers.mail.tracking_settings import TrackingSettings
from sendgrid.helpers.mail.ganalytics import Ganalytics

message = Mail(
    from_email='from@example.com',
    to_emails='to@example.com',
    subject='Sending with Twilio SendGrid is Fun',
    html_content='<strong>and easy to do anywhere, even with Python</strong>')
try:
    tracking_settings = TrackingSettings()
    tracking_settings.ganalytics = Ganalytics(enable=True, utm_medium="email")
    message.tracking_settings = tracking_settings
    sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
    response = sg.send(message)
    print(response.status_code)
    print(response.body)
    print(response.headers)
except Exception as e:
    print(e.message)

Either the module should enforce the use of the Utm_ modules, or check for the presence of primitive str types.

Technical details:

  • sendgrid-python Version: master (latest commit: 610e933)
  • Python Version: 3.7.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions