Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

Log in or register to post/reply in the forum.

API Call with username and password failed

Thein Nov 12, 2022 09:42 AM


I need little bit help on API call with username and password. I found this "http://username:password@http.server.address." 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:password@http.loadsensing.wocs3.com/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:password@https://loadsensing.wocs3.com/11111/dataserver/api/v1/Data/networks/11111"
    Uri_3 = "https://username:password@loadsensing.wocs3.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"))

aa = response_1.content
bb = json.loads(aa)
print("Tilt Readings for T1")
print("TimeStamp =", bb["22222"][3]["value"]["readTimestamp"])
print("X_Tilt =", bb["22222"][3]["value"]["readings"][0]["tilt"])
print("Y_Tilt =", bb["22222"][3]["value"]["readings"][1]["tilt"])
print("Z_Tilt =", bb["22222"][3]["value"]["readings"][2]["tilt"])

 I hope some one can enlighten me about API Call with username and password. Thanks in advace.

Best regards,

Vim Nov 14, 2022 08:48 AM

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

Thein Jan 1, 2023 02:34 AM

Hi Vin,

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.

Best regards,

giulio Jan 2, 2023 10:11 AM

Hi Vin,

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


Log in or register to post/reply in the forum.