python-sparkpost
python-sparkpost copied to clipboard
Documentation incorrect for EU and Enterprise customers
Putting this out there in case other people come across this issue.
Problem
The current documentation for EU and Enterprise customers is incorrect:
For SparkPost EU and Enterprise accounts, pass in a second parameter to set the API host.
from sparkpost import SparkPost
sp = SparkPost('YOUR API KEY', 'https://api.eu.sparkpost.com')
This causes a resolver error:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //api.eu.sparkpost.com/api/v1/transmissions (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe226f75630>: Failed to establish a new connection: [Errno -2] Name or service not known'))
Cause
When the second parameter is passed, the constructor appends "https://" to the string (assuming that a domain will be passed and NOT the base URL). This causes the resultant URL to be https://https://api.eu.sparkpost.com/api/v1/transmissions
, which causes connectivity failure.
Solution
When passing the API host, drop the https://
. Working example:
from sparkpost import SparkPost
sp = SparkPost('YOUR API KEY', 'api.eu.sparkpost.com')