Base64 Authentication Python

前端 未结 4 664
滥情空心
滥情空心 2021-02-01 15:03

I\'m following an api and I need to use a Base64 authentication of my User Id and password.

\'User ID and Password need to both be concatenated and then Base64 encoded\'

4条回答
  •  遇见更好的自我
    2021-02-01 15:23

    You can encode the data and make the request by doing the following:

    import requests, base64
    
    usrPass = "userid:password"
    b64Val = base64.b64encode(usrPass)
    r=requests.post(api_URL, 
                    headers={"Authorization": "Basic %s" % b64Val},
                    data=payload)
    

    I'm not sure if you've to add the "BASIC" word in the Authorization field or not. If you provide the API link, It'd be more clear.

提交回复
热议问题