Python 编码Basic Auth使用方法简单实例
作者:lqh 时间:2023-06-13 22:29:50
本片博文主要介绍在Python3 环境下把用户名密码编码成字符串。
代码如下:
import base64
def get_basic_auth_str(username, password):
temp_str = username + ':' + password
# 转成bytes string
bytesString = temp_str.encode(encoding="utf-8")
# base64 编码
encodestr = base64.b64encode(bytesString)
# 解码
decodestr = base64.b64decode(encodestr)
return 'Basic ' + encodestr.decode()
调用样例:
print(get_basic_auth_str('admin', '123456'))
输出
Basic YWRtaW46MTIzNDU2
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/huplion/article/details/53177227
标签:Python,Basic,Auth
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JS数组合并push与concat区别分析
2024-04-22 22:40:09
PHP结合vue导出excel出现乱码的解决方法分享
2023-05-30 09:18:25
![](https://img.aspxhome.com/file/2023/5/55315_0s.png)
JavaScript实现网页跨年倒计时
2024-06-14 18:24:43
![](https://img.aspxhome.com/file/2023/6/56656_0s.jpg)
python字符串常规操作大全
2021-04-11 17:20:36
![](https://img.aspxhome.com/file/2023/7/80387_0s.png)
用 Python 元类的特性实现 ORM 框架
2022-02-12 12:45:24
![](https://img.aspxhome.com/file/2023/3/127313_0s.png)
Go中recover与panic区别详解
2024-05-10 13:58:22
Postman 使用指南及小技巧
2023-06-23 22:28:38
![](https://img.aspxhome.com/file/2023/7/58167_0s.jpg)
事件触发列表与解说
2013-07-19 11:17:12
Python 同级目录(兄弟目录)调用方式
2021-12-07 15:52:12
![](https://img.aspxhome.com/file/2023/8/134788_0s.png)
python Django模板的使用方法(图文)
2022-03-30 04:23:52
![](https://img.aspxhome.com/file/2023/9/63889_0s.png)
python爬取网易云音乐评论
2021-02-23 11:23:02
详解Tensorflow不同版本要求与CUDA及CUDNN版本对应关系
2021-01-09 10:40:27
![](https://img.aspxhome.com/file/2023/5/103495_0s.png)
利用ASP.NET MVC和Bootstrap快速搭建响应式个人博客站(一)
2023-07-06 23:47:39
![](https://img.aspxhome.com/file/2023/6/56056_0s.jpg)
SQL中concat、concat_ws()、group_concat()的使用与区别
2024-01-21 02:20:26
![](https://img.aspxhome.com/file/2023/0/103570_0s.jpg)
使用SQL实现车流量的计算的示例代码
2024-01-21 21:53:13
![](https://img.aspxhome.com/file/2023/5/91195_0s.jpg)
解决使用openpyxl时遇到的坑
2022-09-03 09:25:37
![](https://img.aspxhome.com/file/2023/3/107143_0s.jpg)
pyhton学习与数据挖掘self原理及应用分析
2023-07-04 23:19:11
Python编程判断这天是这一年第几天的方法示例
2022-01-30 22:38:19
![](https://img.aspxhome.com/file/2023/8/89378_0s.jpg)
sql2005 数据库转为sql2000数据库的方法(数据导出导入)
2024-01-26 07:38:56
![](https://img.aspxhome.com/file/2023/7/108547_0s.jpg)
对python中array.sum(axis=?)的用法介绍
2021-10-27 20:37:04
![](https://img.aspxhome.com/file/2023/4/90614_0s.jpg)