sendgrid-python: HTTP Error 401: Unauthorized
Hello. We experience a lot of 401 errors just after 28 October. Changing API key is not working. Could you say is that ok? We are using sendgrid-python installed from pip like “pip install sendgrid”.
Code:
sg = sendgrid.SendGridAPIClient(api_key=API_KEY)
subject = "Some subject"
from_email = "1@gmail.com"
to_email = "2@gmail.com"
content = Content('text/html', html content)
mail = Mail(Email(from_email), subject, Email(to_email), content)
response = sg.client.mail.send.post(request_body=mail.get())
msg, status = response.body, response.status_code
logging.info(status)
logging.info(msg)
Tried to set ENV variable but it doesn’t help too.
Best regards, Peter
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 19 (8 by maintainers)
I saw the same “Unauthorized” message when I generated the API key using my “teammate” account and apparently it did not have Mail “send” privileges. Worked after I used main admin account or upgrade the teammate permissions.
More about SendGrid “teammates” permissions : https://sendgrid.com/docs/User_Guide/Settings/teammates.html#-Configuring-permisisons
Hi, @thinkingserious ,
thanks, it works now, there is a typo in SENDGRIDKEY
Regards
What is your dev platform? If if it’s a Unix variant, can you go to your shell and type
echo $SENDGRIDKEYto make sure it’s set properly?