Used the example code:
```# using SendGrid's Python Library
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email='[email protected]',
to_emails='[email protected]',
subject='Sending with Twilio SendGrid is Fun',
html_content='and easy to do anywhere, even with Python')
try:
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)
```
changed the print(e.message) to print(e) as I had problems with the previous versions and another issue told me to change it and that got rid of all the red stuff.
Now when trying to send, I get the "blue error":
Whereas xxxx is a 4 digit number, wasn't sure if I should include it ;)
So, does anyone have the clue what's going wrong?
I tried importing certifi and ssl, though no change.
Is there any update on this? I'm getting same error here.
+1 here
I found it will be working in ubuntu but hit the issue in windows-2019, I got it workarounded in ubuntu.
Looks like a generic python issue. Recommend trying solutions provided here: https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error
This worked for me:
import ssl
context = ssl._create_unverified_context()
sg = SendGridAPIClient(os.environ.get("********"))
response = sg.send(message)
I am still struggling this issue!
Check the Python version you are using with python --version in your project when your virtual environment is activated.
Find the corresponding Python folder /Applications/Python*.
Run the following script: Install Certificates.command
In my case I have two version of Python installed and when ran the script for a wrong version of Python used in my project (wrong Python folder inside Applications), the problem persisted. After running the script for the correct Python version, I could send emails without a problem