[SOLVED] "Authentication credentials were not provided" - but they were! (Python)

Hi,

I’m using Python Requests to submit readings for multiple variables at once. The headers of the request object are being created correctly:

{'Content-Length': '478', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json; indent=4', 'User-Agent': 'python-requests/2.5.1 CPython/2.7.3 Linux/3.12.35+', 'Connection': 'keep-alive', 'X-Auth-Token': 'abc123abc123abc123abc123abc123abc', 'Content-Type': 'application/json'}

But the response is that “Authentication credentials were not provided.” The “X-Auth-Token” header is clearly there, so I’d be grateful if anyone has any suggestions for what I’m doing wrong!

Many thanks,
Haydn

Hi Haydn, this is a example using python requests library:

import requests
headers = {'Content-Type': 'application/json', 'X-Auth-Token': 'asdfasdfasdfasdfasdfasdf'}
requests.get("http://things.ubidots.com/api/v1.6/datasources/", headers=headers)

Then you will have a 200 status code response from the server.

Maybe if you send some code we can find the error.

Regards,
Gustavo.

Hi Gustavo,

Thanks for the quick response. Here is the code:

headers = {'Accept': 'application/json; indent=4', 'Content-Type': 'application/json', 'X-Auth-Token': self.APIKey}
url = "http://things.ubidots.com/api/v1.6/collections/values"
try:
    req = requests.post(url, data=json.dumps(payload), headers=headers)

‘payload’ is defined and filled elsewhere, but here’s what it looks like once constructed:

[{"variable": "54e8feba762542435f3b65c0", "value": 21.4}, {"variable": "54e8fed17625423c95eccbc7", "value": 1005.0866895310136}, {"variable": "54e8fee676254240d5d984e5", "value": null}, {"variable": "54e8ff037625424093180fbd", "value": null}, {"variable": "54e8ff46762542424dfed256", "value": 31448.275862068964}, {"variable": "54e8ff5e7625423e6921c5eb", "value": 34868.42105263158}, {"variable": "54e8ff737625424208809357", "value": 203560.83086053416}]

Regards,
Haydn

Hi @haydnw, an observation just in case: make sure you are using a token in your request and not an API Key.
Best,
Agustín

Oh no, a schoolboy error! :slight_smile: Thanks very much, working perfectly now. Code is available in the outputs directory of my fork of the AirPi project, if anyone’s interested: https://github.com/haydnw/AirPi

1 Like

@haydnw, thanks for including Ubidots in your AirPi version. We’ll give it a try with our AirPi module.