Hi - I am trying to use Nick’s python program : TTS.DataStorage.Tab.py to retrieve data from the storage integration. When I run the code I get:
Fetching from data storage …
URL: https://eu1.cloud.thethings.network/api/v3/as/applications/mydeviceid/packages/storage/uplink_message?order=received_at&type=uplink_message&after=2021-07-08T14:27:00Z
Status: 401
Traceback (most recent call last):
File "c:/Python37/TTS.DataStorage.Tab.py", line 57, in <module>
someJSON = json.loads(theJSON)
File "C:\Python37\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python37\lib\json\decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 403 (char 402)
If I type the url above directly into a browser, then it downloads the data into the browser, no problem.
Then I added the line : print(r.text) to the code in order to see what the outcome was, and I see:
{"error":{"grpc_code":16,"http_code":401,"message":"error:pkg/identityserver:invalid_authorization (invalid authorization)","http_status":"Unauthorized","details":[{"@type":"type.googleapis.com/ttn.lorawan.v3.ErrorDetails","namespace":"pkg/identityserver","name":"invalid_authorization","message_format":"invalid authorization","correlation_id":"f8bdcc8c37814568b04afc4448d92405","code":16}]}}
Edit - Seems to be an issue with the API key?? I generated an API key and copied it, it is in the list of keys
Or is it a decoder issue?
Solved - I recreated an API key, solved the issue
Thanks
Russell
Do you have some utility the allows you to set the authentication header?
Which browser?
The whole point of the API security is to stop me sitting here and ‘exploring’ your data storage or indeed any number of the API calls. So it would be interesting to know if you’ve managed to find a way around it.
Hi Nick, I’m simply typing the URL into my Chrome browser. Nothing more. So yes, that would seem to be a concern if anyone could do it. Perhaps TTN recognizes my pc’s IP address and authorizes the request.
As an experiment I tried the same thing using my phone to reach that URL and it rejected the request (as it should), so I think that it means I can only do it on the local machine.
I tried from Postman (on my same PC) and it returns:
{
"code": 12,
"message": "Not Implemented"
}
So I think we’re ok.
Further: I tried it from my Edge Browser and it didn’t authorize either. It seems like Chrome is allowing it (only from my local machine ?)
I can experiment further if need be. Although it does seem that it can only be done from my pc.
Can you simulate the issue at your end?
Yeah, I thought of that in the first instance but no joy - I’ll have to do a browser restart as I use Safari for general and Chrome for server admin (my servers, TTN etc) so I can start with a clean slate.