Python 编码Basic Auth使用方法简单实例,pythonauth
Python 编码Basic Auth使用方法简单实例,pythonauth
本片博文主要介绍在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
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关内容
- Python正则表达式完全指南,python完全指南
- python爬虫入门教程--利用requests构建知乎API(三),py
- python win32 简单操作方法,pythonwin32
- Python win32com 操作Exce的l简单方法(必看),win32comexce
- python爬虫入门教程--HTML文本的解析库BeautifulSoup(四),
- python爬虫入门教程--正则表达式完全指南(五),pyth
- 详解Python3操作Mongodb简明易懂教程,详解python3mongodb
- python 如何快速找出两个电子表中数据的差异,python电子
- 利用Python实现网络测试的脚本分享,python实现脚本分享
- Python编程对列表中字典元素进行排序的方法详解,pyt
评论关闭