Python Forum

Full Version: Unable to get the data from web API using authentication key
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi team,

I have generated token key and when try to pass request to get the data from API using token key, facing below error message.

"D:\Users\lth\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\ InsecureRequestWarning: Unverified HTTPS request is being made to host ''. Adding certificate verification is strongly advised. See:
<!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">"

Could you please help me on this.

import requests

# API URL to generate authentication token key
apiURL_auth = ""
token_dict = """<authRequest>
headers1 = {"Content-Type": "application/xml"}
response =, data=token_dict, headers=headers1)
auth_token = response.text
index_1 = auth_token.index("<authToken>")
index_2 = auth_token.index("</authToken>")
index_3 = auth_token.index("<errorCode>")
index_4 = auth_token.index("</errorCode>")
error_code = auth_token[index_3:index_4].replace("<errorCode>","")
token_Key = auth_token[index_1:index_2].replace("<authToken>","")

# API URL for module data
apiURL_main =""
header2 = {"Authorization": "MaaS token=%s" % token_Key}
response2 = requests.get(apiURL_main, headers=header2, verify=False)