Commit 1ee10fd introduced support for v2 api_key naming and tries to fetch the api_key attribute if available. If self._apikey has already been set by the apikey attribute then self._apikey will be overwritten with a (possibly non-existing) environment variable when api_key is missing. This results in a 401 Unauthorized response from Sendgrid as no API-key is present.
To reproduce remove enviroment variable for key and set it directly when constructing SendGridAPIClient:
mySendGrid = sendgrid.SendGridAPIClient(apikey="THISISMYKEY)
The above does not work however the following with v2 naming works and serves as a work-around:
mySendGrid = sendgrid.SendGridAPIClient(api_key="THISISMYKEY)
Commit 1ee10fd introduced support for v2 api_key naming and tries to fetch the api_key attribute if available. If self._apikey has already been set by the apikey attribute then self._apikey will be overwritten with a (possibly non-existing) environment variable when api_key is missing. This results in a 401 Unauthorized response from Sendgrid as no API-key is present.
To reproduce remove enviroment variable for key and set it directly when constructing SendGridAPIClient:
mySendGrid = sendgrid.SendGridAPIClient(apikey="THISISMYKEY)
The above does not work however the following with v2 naming works and serves as a work-around:
mySendGrid = sendgrid.SendGridAPIClient(api_key="THISISMYKEY)