This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: imaplib fails during login
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Imap lib implicit conversion from bytes to string
View: 6734
Assigned To: Nosy List: debatem1, marcin.bachry
Priority: normal Keywords:

Created on 2009-09-12 20:05 by debatem1, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg92552 - (view) Author: geremy condra (debatem1) Date: 2009-09-12 20:05
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.
msg92593 - (view) Author: Marcin Bachry (marcin.bachry) Date: 2009-09-14 08:32
Looks like duplicate of #6734.
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51146
2010-01-15 18:32:33r.david.murraysetstatus: open -> closed
resolution: duplicate
priority: normal
type: behavior
superseder: Imap lib implicit conversion from bytes to string
stage: resolved
2009-09-14 08:32:43marcin.bachrysetnosy: + marcin.bachry
messages: + msg92593
2009-09-12 20:05:57debatem1create