Sendgrid-python: Send grid not working with python 3.5.2

Created on 5 Apr 2019  路  8Comments  路  Source: sendgrid/sendgrid-python

Hi ,

I am trying to send email using following code in python version 3,5,2 and sendgrid 6.0.2
from sendgrid import *
from sendgrid.helpers.mail import *
import base64
import sys

from_email = Email("from")
to_email = Email("t0")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "a")
mail = Mail(from_email, subject, to_email, content)
sg = sendgrid.SendGridAPIClient("key")
data = mail.get()
response = sg.client.mail.send.post(request_body=data)

it is giving me following error
TypeError: is not JSON serializable

  • sendgrid-python Version: master (latest commit: [commit number]) 6.0.2
  • Python Version: 3.5.2
unknown or a waiting for feedback question

Most helpful comment

Seems like a crazy breaking change (reordering parameters) to push out to people automatically via a new package version.

All 8 comments

Hello @dijaitly,

The equivalent code in sendgrid-python v6.0.2 can be found here.

You would be replacing:

mail = Mail(from_email, subject, to_email, content)

with

mail = Mail(from_email, to_email, subject, content)

and

data = mail.get()
response = sg.client.mail.send.post(request_body=data)

with

response = sg.send(mail)

With Best Regards,

Elmer

Hi followed the insturction on link it works..

I followed the instruction on the link provided..

it works.. thanks..

Seems like a crazy breaking change (reordering parameters) to push out to people automatically via a new package version.

Hello @stefangordon,

Please see this issue with respect to the refactor.

Since we hope to very rarely make breaking changes, I tried to fix bad design issues while we had the hood up, so to speak. One of those bad decisions was the original ordering of the parameters.

We used the semver custom of specifying a major version bump to avoid breaking changes being introduced to folks via auto-update. In your case, how did this major version bump slip through into production? I'd like to learn from you to avoid this issue in the future (that said, I'm really hoping we don't need a breaking change in the foreseeable future).

Thanks for the feedback!

With Best Regards,

Elmer

Thanks @thinkingserious, I understand sometimes it is necessary to make these changes. In my case we publish a library on PyPi and we do not pin any package versions as we understand it to be best practice - as such the library just stopped working for users after a deployment one day.

I suppose if you want to make this change you could make an entirely new method name with your new parameters and mark the old one as deprecated for a while so people have lots of time to see warnings about deprecation before it goes away. Of course this makes it take much longer to complete the transition.

Hello @stefangordon,

Thank you for taking the time to provide thoughtful feedback, I really appreciate it!

I've added your thoughts to our internal notes around improving our developer experience around our helper libraries.

Cheers!

With Best Regards,

Elmer

edit:

NVM, i see that there were substantial changes to the API .. I fixed my code.

Seems like a crazy breaking change (reordering parameters) to push out to people automatically via a new package version.

It's safer to always specify the arg name when calling a function. It increases readability and order doesn't matter.

Was this page helpful?
0 / 5 - 0 ratings