使用imaplib,我正在尝试连接到邮件服务器。 当我将密码作为普通字符串包含时:“password” 连接良好。但是我正在尝试稍微混淆我的密码,所以我之前已经通过b64encode运行了它,然后在登录中使用了b64decode:
#Works:
mail.login('myloginname', 'myPassword')
#Doesn't Work:
mail.login('myloginname', base64.b64decode('Ja3rHsnakhdgkhervc'))
# or
mail.login('myloginname', bytes(base64.b64decode('Ja3rHsnakhdgkhervc')))
。。。你知道吗
Traceback (most recent call last):
File "./testing.py", line 15, in <module>
mail.login('myloginname', bytes(base64.b64decode('Ja3rHsnakhdgkhervc')))
File "/usr/local/lib/python3.4/imaplib.py", line 536, in login
typ, dat = self._simple_command('LOGIN', user, self._quote(password))
File "/usr/local/lib/python3.4/imaplib.py", line 1125, in _quote
arg = arg.replace('\\', '\\\\')
TypeError: 'str' does not support the buffer interface
建议?你知道吗
您传递的是一个
bytes
对象作为密码,而不是str
值,因为base64.b64decode()
会返回这个值。你知道吗您必须将值解码为字符串:
异常是由
bytes.replace()
方法引起的,该方法需要bytes
参数。因为'\\'
和'\\\\'
是str
对象,所以在args.replace('\\', '\\\\')
得到回溯仅仅是因为args
是bytes
对象:相关问题 更多 >
编程相关推荐