Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imaplib.IMAP4() ends with "Name or service not known" on Fedora 18 #62740

Closed
sYnfo mannequin opened this issue Jul 24, 2013 · 15 comments
Closed

imaplib.IMAP4() ends with "Name or service not known" on Fedora 18 #62740

sYnfo mannequin opened this issue Jul 24, 2013 · 15 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@sYnfo
Copy link
Mannequin

sYnfo mannequin commented Jul 24, 2013

BPO 18540
Nosy @warsaw, @mcepl, @bitdancer, @berkerpeksag, @zvyn
PRs
  • bpo-18540: Fix EAI_NONAME in imaplib.IMAP4*() #8634
  • [3.7] bpo-18540: Fix EAI_NONAME in imaplib.IMAP4*() (GH-8634) #8697
  • [3.6] bpo-18540: Fix EAI_NONAME in imaplib.IMAP4*() (GH-8634) #8698
  • Files
  • imaplib.patch: Substitutes '' for None as the default value for host in imaplib.py
  • imaplib-zvyn.patch: Substitutes '' for 'localhost' as the default value for host in imaplib.py
  • imaplib_interpret_empty_string_as_None.patch
  • imaplib_interpret_empty_string_as_NoneV2.patch
  • imaplib_interpret_empty_string_as_None-final.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-08-07.02:38:52.606>
    created_at = <Date 2013-07-24.09:19:31.148>
    labels = ['3.7', '3.8', 'type-bug', 'library', 'expert-email']
    title = 'imaplib.IMAP4() ends with "Name or service not known" on Fedora 18'
    updated_at = <Date 2018-08-07.02:38:52.546>
    user = 'https://bugs.python.org/sYnfo'

    bugs.python.org fields:

    activity = <Date 2018-08-07.02:38:52.546>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-08-07.02:38:52.606>
    closer = 'berker.peksag'
    components = ['Library (Lib)', 'email']
    creation = <Date 2013-07-24.09:19:31.148>
    creator = 'sYnfo'
    dependencies = []
    files = ['31027', '34271', '35903', '35904', '40347']
    hgrepos = []
    issue_num = 18540
    keywords = ['patch']
    message_count = 15.0
    messages = ['193632', '193655', '193663', '193665', '212603', '218704', '222576', '222577', '222578', '249708', '249750', '315559', '323231', '323232', '323233']
    nosy_count = 7.0
    nosy_names = ['barry', 'mcepl', 'r.david.murray', 'berker.peksag', 'sYnfo', 'dveeden', 'zvyn']
    pr_nums = ['8634', '8697', '8698']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue18540'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    @sYnfo
    Copy link
    Mannequin Author

    sYnfo mannequin commented Jul 24, 2013

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib64/python2.7/imaplib.py", line 163, in __init__
        self.open(host, port)
      File "/usr/lib64/python2.7/imaplib.py", line 229, in open
        self.sock = socket.create_connection((host, port))
      File "/usr/lib64/python2.7/socket.py", line 553, in create_connection
        for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    socket.gaierror: [Errno -2] Name or service not known

    Steps to Reproduce:

    1. run python interpreter
    2. import imaplib
    3. imaplib.IMAP4()

    Expected behavior would be, as per documentation, for imaplib to try to connect to localhost.

    The root cause is, I believe, this:

    socket.py::create_connection states "An host of '' [...] tells the OS to use the default." and thus imaplib uses '' as the default value for host, however from getaddrinfo (to which function the host variable is passed) documentation and source it seems to me that it expect None, not '' as the default value.

    Substituting '' for None as the default value for host in imaplib.py seems to resolve this issue, I've included a tentative patch that does just that.

    In case this will need patching I'd be more than happy to work on a more complete patch! :)

    @sYnfo sYnfo mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 24, 2013
    @bitdancer
    Copy link
    Member

    So this represents a change in behavior of the socket library on Fedora 18 vs earlier versions? Do any of the impalib tests fail?

    @sYnfo
    Copy link
    Mannequin Author

    sYnfo mannequin commented Jul 24, 2013

    So this represents a change in behavior of the socket library on Fedora 18 vs earlier versions?

    I don't believe so. This happens on my Fedora 18 system, my Debian box with Python 2.6.6, on Fedora 19 (https://bugzilla.redhat.com/show_bug.cgi?id=987340), another Debian system (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=591471) and python compiled from the default branch does the same thing.

    The documentation for imaplib.IMAP4 says:
    "If host is not specified, '' (the local host) is used."

    My point is that imaplib.IMAP4 without any arguments should try to connect to localhost, however this is not what is currently happening, at least on the systems mentioned above. Why I think this is happening I've tried to explain in my previous comment.

    Do any of the impalib tests fail?
    Nope.

    @bitdancer
    Copy link
    Member

    OK, yeah, this seems to be long standing, untested behavior. I will take a look at what should be done here.

    @zvyn
    Copy link
    Mannequin

    zvyn mannequin commented Mar 2, 2014

    According to the documentation1 the values for host should be set to 'localhost' by default. I attached a patch that does just that. Also note, that the minimal example at the end of 1 is broken by this bug.

    @bitdancer
    Copy link
    Member

    Milan: using 'localhost' is incorrect, since the string 'localhost' will not always resolve to the local host IP, while passing None to getaddrinfo will.

    It is significant that the example fails. We need a test for this case (the imap tests have been historically very poor, though we've improved that somewhat in the past few years).

    Although it is a low-probability thing, someone might be depending on self.host being '' by default, so I think the better (and simpler) fix is to convert '' to None in the _create_socket method.

    @zvyn
    Copy link
    Mannequin

    zvyn mannequin commented Jul 8, 2014

    I patched it as you suggested (9 lines added/changed in total).

    @zvyn
    Copy link
    Mannequin

    zvyn mannequin commented Jul 8, 2014

    Ignore what I just did (the test is obviously dump; it fails if you run it on an IMAP server). I'll make a new attempt after a coffee break ;)

    @zvyn
    Copy link
    Mannequin

    zvyn mannequin commented Jul 8, 2014

    I'm still wondering if the test could be done better. At least it fixes the bug.

    @zvyn
    Copy link
    Mannequin

    zvyn mannequin commented Sep 4, 2015

    I shouldn't criticize my own patches if I want to have them committed:
    Here comes the final and perfect patch for this issue ;)
    (I only rephrased the comment for the test to make the intuition clear.)

    @berkerpeksag
    Copy link
    Member

    Hi Milan, thanks for the updated patch. Did you see my review comments? http://bugs.python.org/review/18540/

    @mcepl
    Copy link
    Mannequin

    mcepl mannequin commented Apr 21, 2018

    ping?

    @berkerpeksag
    Copy link
    Member

    New changeset e4dcbbd by Berker Peksag in branch 'master':
    bpo-18540: Fix EAI_NONAME in imaplib.IMAP4*() (GH-8634)
    e4dcbbd

    @berkerpeksag
    Copy link
    Member

    New changeset 5799e5a by Berker Peksag (Miss Islington (bot)) in branch '3.7':
    bpo-18540: Fix EAI_NONAME in imaplib.IMAP4*() (GH-8634)
    5799e5a

    @berkerpeksag
    Copy link
    Member

    New changeset 671a13a by Berker Peksag (Miss Islington (bot)) in branch '3.6':
    bpo-18540: Fix EAI_NONAME in imaplib.IMAP4*() (GH-8634)
    671a13a

    @berkerpeksag berkerpeksag added 3.7 (EOL) end of life 3.8 only security fixes labels Aug 7, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants