我试图在Python3中建立HTTPS连接,当我try 对用户名和密码进行编码时,base64
encodebytes
方法会在"\n"结尾处返回编码值,因此我在try 连接时出错.
有没有办法告诉base64
库在编码时不要附加一个新行字符,或者删除这个新行字符的最佳方法是什么?我try 使用replace
方法,但出现以下错误:
Traceback (most recent call last):
File "data_consumer.py", line 33, in <module>
auth_base64 = auth_base64.replace('\n', '')
TypeError: expected bytes, bytearray or buffer compatible object
我的代码:
auth = b'username@domain.com:passWORD'
auth_base64 = base64.encodebytes(auth)
auth_base64 = auth_base64.replace('\n', '')
有什么 idea 吗?谢谢