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\connectionpool.py:979: InsecureRequestWarning: Unverified HTTPS request is being made to host 'services.fiberlink.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest...l-warnings
warnings.warn(
<!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 = "https://services.fiberlink.com/auth-apis/auth/1.0/authenticate/1008860"
token_dict = """<authRequest>
                <maaS360AdminAuth>
                    <billingID>1008860</billingID>
                    <platformID>3</platformID>
                    <appID>com.1008860.api</appID>
                    <appVersion>1.0</appVersion>
                    <appAccessKey>XXXXXXXX</appAccessKey>
                    <userName>XXXXXXXX</userName>
                    <password>XXXXXXXX</password>
                </maaS360AdminAuth>
            </authRequest>
"""
headers1 = {"Content-Type": "application/xml"}
response = requests.post(apiURL_auth, 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>","")
print(token_Key)


# API URL for module data
apiURL_main ="https://services.fiberlink.com/device-apis/devices/1.0/search/1008860/?deviceStatus=Active&partialDeviceName=UKC0"
header2 = {"Authorization": "MaaS token=%s" % token_Key}
response2 = requests.get(apiURL_main, headers=header2, verify=False)
print(response2.text)