I need little bit help on API call with username and password. I found this "http://username:firstname.lastname@example.org." on the help file of CR6 CR Basic programinng, so I tried I few codes as trial and error as follows, but nothing seems working. The datalogger I am using is CR6 and internet is from office ethernet connection. I have other API calls with token in the same program, all working well, except this web server address, "https://loadsensing.wocs3.com/11111/dataserver/api/v1/data/networks/11111", which need username and password.
'Uri_3 = "https://username:email@example.com/11111/dataserver/api/v1/Data/networks/11111" 'Uri_3 = "https://username:firstname.lastname@example.org/11111/dataserver/api/v1/Data/networks/11111" 'Uri_3 = "https://username:password@https://loadsensing.wocs3.com/11111/dataserver/api/v1/Data/networks/11111" Uri_3 = "https://username:email@example.com/11111/dataserver/api/v1/Data/networks/11111" HTTPGet (Uri_3,WS_Api,"",7500) 'Time out 75Sec
The python code that works for the API call is as follows:-
import json import requests from requests.auth import HTTPBasicAuth uri_3 = "https://loadsensing.wocs3.com/11111/dataserver/api/v1/data/networks/11111" response_1 = requests.get(uri_3, auth=HTTPBasicAuth("username", "password")) print(response_1.content) aa = response_1.content bb = json.loads(aa) print() print("Tilt Readings for T1") print("TimeStamp =", bb["22222"]["value"]["readTimestamp"]) print("X_Tilt =", bb["22222"]["value"]["readings"]["tilt"]) print("Y_Tilt =", bb["22222"]["value"]["readings"]["tilt"]) print("Z_Tilt =", bb["22222"]["value"]["readings"]["tilt"])
I hope some one can enlighten me about API Call with username and password. Thanks in advace.
You could try using the header with the following syntax:
"Authorization: Basic [insert authentication hash]"
Example below is using admin/admin as the username and password hash
HTTPGet (Uri_3,WS_Api,"Authorization: Basic YWRtaW46YWRtaW4=",7500) 'Time out 75Sec
Thanks for your import and advice. Sorry for the delay reply as I was doing quite a lot of trials and errors to find out which solution works. I tried as you advised, it doesnot work either. Now, gave up getting the data by a datalogger and I run a python code to retrieve the data with a PC. So far, It works well. Thanks for your help.
I'm trying to run python code to retrieve data froma CR1000 without success.
I'm running a linux box connected with a serial USB adapter: I'm using an old library script (pycr1000).
Could you give me some advice ?
Thanks for help