سؤال

I've been trying to connect to my Gmail account using python. imap is enabled.

import imaplib

imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
# also tried imap_server = imaplib.IMAP4_SSL("imap.gmail.com"), doesnt work. 

Traceback is :

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 1202, in __init__
    IMAP4.__init__(self, host, port)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 172, in __init__
    self.open(host, port)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 1217, in open
    IMAP4.open(self, host, port)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 248, in open
    self.sock = self._create_socket()
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 1205, in _create_socket
    sock = IMAP4._create_socket(self)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 238, in _create_socket
    return socket.create_connection((self.host, self.port))
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socket.py", line 435, in create_connection
    raise err
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socket.py", line 426, in create_connection
    sock.connect(sa)
OSError: [Errno 65] No route to host
هل كانت مفيدة؟

المحلول

What OSError: [Errno 65] No route to host means is what it say: you can't get to that machine from your machine.

You can test that from outside of Python by opening up a terminal/DOS prompt and typing this:

ping imap.gmail.com

It's possible that this is actually a name lookup error, and you're somehow getting a bad address for imap.gmail.com. So, just to be sure, check by IP address too:

ping 74.125.129.108
ping 74.125.129.109

If ping works, you can check whether your router is for some reason just blocking TCP access to the host, e.g., with:

telnet imap.gmail.com

If it's working, this should either hang for a long time, or give you a connection-refused error; if it gives you a no-route-to-host error, it's the same problem you're seeing.

It's also possible that your router is specifically blocking port 993. You can test this too:

telnet imap.gmail.com 993

If it doesn't come back with something like "Connected to gmail-imap.l.google.com", same problem here too.

At any rate, once you've verified that this is a system or network configuration problem, not a programming problem, go ask for help with your system on the appropriate site.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top