sklarsa / django-sendgrid-v5

An implementation of Django's EmailBackend compatible with sendgrid-python v5+
MIT License
319 stars 54 forks source link

How to solve 401 Unauthorized issue ? #11

Closed AdrienLemaire closed 6 years ago

AdrienLemaire commented 6 years ago

I tried to whitelist the ips, then tried to disable whitelisting from Sendgrid, but I keep getting this error when sending an email:

[ERROR] exception
HTTP Error 401: Unauthorized
{'reason': 'Unauthorized', 'body': b'{"errors":[{"message":"The requestor\'s IP Address is not whitelisted","field":null,"help":null}]}', 'headers': <http.client.HTTPMessage object at 0x7f6e8da4d898>, 'status_code': 401}

Any idea why that could be ?

AdrienLemaire commented 6 years ago

Got it, I didn't have the environment variable SENDGRID_API_KEY, I had only set the django settings variable. From your documentation, it was really far from obvious that the env var was mandatory. Moreover, I had a successful run when I ran it locally with runserver (only fails on prod with gunicorn).. Might be a good idea to update the doc with this info

sklarsa commented 6 years ago

Well really, only the SENDGRID_API_KEY in settings.py needs to be set. Which exact method you use depends on the way your application is set up to inject secrets (like API keys) into configs. My example makes use of environment variables, but it's only one way of doing things. I just didn't want to include an example with a hardcoded API key, because you probably shouldn't do that.

Either way, I updated the readme to reflect this. If you think it needs more clarification, I'm happy to accept any PRs!