Base64 身份验证 Python [英] Base64 Authentication Python

查看:23
本文介绍了Base64 身份验证 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注一个 api,我需要对我的用户 ID 和密码使用 Base64 身份验证.

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

'用户 ID 和密码都需要连接,然后 Base64 编码'

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

然后显示示例

'userid:password'

然后继续说在授权标头"中提供编码值'

It then proceeds to say 'Provide the encoded value in an "Authorization Header"'

'例如:授权:BASIC {Base64-encoded value}'

如何将其写入 python api 请求?

How do I write this into a python api request?

z = requests.post(url, data=zdata )

谢谢

推荐答案

您可以通过执行以下操作对数据进行编码并发出请求:

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)

我不确定您是否必须在授权"字段中添加BASIC"字样.如果你提供 API 链接,那就更清楚了.

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.

这篇关于Base64 身份验证 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆