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

查看:143
本文介绍了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编码的值} '

如何将其写入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天全站免登陆