-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Comments
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:
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! :) |
So this represents a change in behavior of the socket library on Fedora 18 vs earlier versions? Do any of the impalib tests fail? |
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: 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.
|
OK, yeah, this seems to be long standing, untested behavior. I will take a look at what should be done here. |
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. |
I patched it as you suggested (9 lines added/changed in total). |
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 ;) |
I'm still wondering if the test could be done better. At least it fixes the bug. |
I shouldn't criticize my own patches if I want to have them committed: |
Hi Milan, thanks for the updated patch. Did you see my review comments? http://bugs.python.org/review/18540/ |
ping? |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: