This article mainly introduces the relevant information of Python Simple examples of how to use coding Basic Auth. Friends who need it can refer to it
This blog post mainly introduces the user in the Python3 environment The first name password is encoded into a string.
The code is as follows:
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()
Calling example:
print(get_basic_auth_str('admin', '123456'))
Output
Basic YWRtaW46MTIzNDU2
The above is the detailed content of Python example analysis on how to use coding Basic Auth. For more information, please follow other related articles on the PHP Chinese website!