如果在webhosting上运行脚本,则无法访问网络

时间:2013-05-05 13:46:45

标签: python python-2.7

下一个脚本在我的mac上正常运行。当我尝试在我的WebHosting(bluehost)上运行它时,我得到socket.error: [Errno 101] Network is unreachable。我知道如何解决它?

#!/usr/bin/python
# Required header that tells the browser how to render the text.
print "Content-type: text/html\r\n\r\n";

import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('user@gmail.com', 'password')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.
print mail.list()


Traceback (most recent call last):
  File "test2.py", line 6, in <module>
    mail = imaplib.IMAP4_SSL('imap.gmail.com')
  File "/home4/user/python27/lib/python2.7/imaplib.py", line 1148, in __init__
    IMAP4.__init__(self, host, port)
  File "/home4/user/python27/lib/python2.7/imaplib.py", line 163, in __init__
    self.open(host, port)
  File "/home4/user/python27/lib/python2.7/imaplib.py", line 1159, in open
    self.sock = socket.create_connection((host, port))
  File "/home4/user/python27/lib/python2.7/socket.py", line 571, in create_connection
    raise err
socket.error: [Errno 101] Network is unreachable

他们的支持根本没有帮助。

可以是端口相关的还是SSL?

1 个答案:

答案 0 :(得分:1)

在bluehosts help pages上,他们提到传出的连接是受限制的,所以问题不在你的程序中。允许出站连接的唯一方法似乎是为此付出代价。