python - Py3.4 IMAPLib Login... 'str' does not support the buffer interface -


using imaplib, i'm trying connect mailserver. when include password normal string: 'password' connects fine. i'm trying obfuscate password, had run through b64encode, , used b64decode in login:

#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' not support buffer interface 

suggestions?

you passing in bytes object password, not str value, because that's base64.b64decode() returns.

you'd have decode value string:

 base64.b64decode('ja3rhsnakhdgkhervc').decode('ascii') 

the exception caused bytes.replace() method, expects bytes arguments. since '\\' , '\\\\' str objects, traceback @ args.replace('\\', '\\\\') because args bytes object:

>>> b'foo'.replace('\\', '\\\\') traceback (most recent call last):   file "<stdin>", line 1, in <module> typeerror: bytes-like object required, not 'str' >>> 'foo'.replace('\\', '\\\\') 'foo' 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -