Reputation: 441
When send the post request it returns a 401 error. Is there anything in the setup that might be causing the error. Here is the code:
import requests
>>>url= 'https://us-street.api.smartystreets.com/street-address'
>>>payload = {'auth-id':'xxxxxx','auth-token':'xxxxx'}
>>>body = [{"street":"1 Santa Claus","city":"North Pole","state":"AK","candidates":10},{"addressee":"Apple Inc","street":"1 infinite loop","city":"cupertino","state":"CA","zipcode":"95014","candidates":10}]
>>>headers = {'Content-Type':'application/json; charset=utf-8', 'Host':'us-street.api.smartystreets.com'}
>>>r = request.post(url, data=payload, json=body, headers=headers)
>>>r.status_code
401
>>>r.url
https://us-street.api.smartystreets.com/street-address
Any help would be appreciated. Link to api documentation: https://smartystreets.com/docs/cloud/us-street-api
Upvotes: 2
Views: 904
Reputation: 6902
According to the documentation, your auth credentials should be in the URL's query string, not in the body. So use params=payload
instead of data=payload
.
Basically, as the API does not find your auth credentials in the right place, it assumes you are not authenticaled/signed in, hence the 401 status code.
Upvotes: 3