Closed asing012 closed 4 years ago
I looked at your repo, this doesn't look like an issue with sendgrid, more your code.
_SendGridAPIClient(os.environ.get('$SENDGRID_APIKEY'))
you're getting your apikey from your environment, your cron user probably doesn't have the same as your normal user.
@kalkaran thanks for your comment. I did check the cron user, it has the same environment variable. Do you think adding the API Key instead of the environment variable will work?
Have you considered setting up a txt file and having the variables you pass (api key, message,...) output into it, and having it triggered by cron? That should show what you don't have access to.
Personally I got round this issue but setting up a screen environment and leaving my python script running in it.
Hi @asing012,
It looks like you might be grabbing your SENDGRID_API_KEY
environment variable incorrectly. Note that the correct way to initialize your SendGridAPIClient
object is:
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
It's a subtle difference, but your code was looking for an environment variable called $SENDGRID_API_KEY
instead of SENDGRID_API_KEY
.
@eshanholtz thank you for the comment. It is working now.
If you have this problem but your API is valid, it might be that your IP is not correctly whitelisted
Hey guys! I am getting the HTTP Error 401. It works fine when I directly run the code. But I am trying to automate it using cronjob on Ubuntu and it keeps giving me this error. I have also tested my API key by sending a request to "https://sendgrid.com/docs/for-developers/sending-email/curl-examples/#-Hello-World".
Any help would be appreciated!