[issue6897] imaplib fails during login

geremy condra report at bugs.python.org
Sat Sep 12 22:05:58 CEST 2009


New submission from geremy condra <debatem1 at gmail.com>:

Getting the following issue- this code:

#! /usr/bin/env python3

import getpass, imaplib

M = imaplib.IMAP4_SSL("imap.gmail.com")
M.login(<username>, <password>)
M.select()
typ, data = M.search(None, 'ALL')
for num in data[0].split():
    typ, data = M.fetch(num, '(RFC822)')
    print('Message %s\n%s\n' % (num, data[0][1]))
M.close()
M.logout()

taken almost verbatim from the documentation, produces this error:

Traceback (most recent call last):
  File "./imaptest.py", line 6, in <module>
    M.login(<username>, <password>)
  File "/usr/lib/python3.0/imaplib.py", line 514, in login
    typ, dat = self._simple_command('LOGIN', user, self._quote(password))
  File "/usr/lib/python3.0/imaplib.py", line 1072, in _quote
    arg = arg.replace(b'\\', b'\\\\')
TypeError: Can't convert 'bytes' object to str implicitly

username and password obviously redeacted.

Changing imaplib.py's _quote function to this:

    def _quote(self, arg):

        arg = arg.replace('\\', '\\\\')
        arg = arg.replace('"', '\\"')

        return '"' + arg + '"'

seems to resolve the issue.

----------
components: Library (Lib)
messages: 92552
nosy: debatem1
severity: normal
status: open
title: imaplib fails during login
versions: Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6897>
_______________________________________


More information about the Python-bugs-list mailing list