2012-05-17 70 views
3

我正在运行搜寻器,它在MAC和Ubuntu系统中工作正常。 当我在Windows上运行它,它会导致以下堆栈跟踪:Python机械化连接失败问题

File "build\bdist.win32\egg\mechanize\_mechanize.py", line 203, in open 
    return self._mech_open(url, data, timeout=timeout) 
    File "build\bdist.win32\egg\mechanize\_mechanize.py", line 230, in _mech_open 
    response = UserAgentBase.open(self, request, data) 
    File "build\bdist.win32\egg\mechanize\_opener.py", line 193, in open 
    response = urlopen(self, req, data) 
    File "build\bdist.win32\egg\mechanize\_urllib2_fork.py", line 344, in _open 
    '_open', req) 
    File "build\bdist.win32\egg\mechanize\_urllib2_fork.py", line 332, in _call_chain 
    result = func(*args) 
    File "build\bdist.win32\egg\mechanize\_urllib2_fork.py", line 1170, in https_open 
    return self.do_open(conn_factory, req) 
    File "build\bdist.win32\egg\mechanize\_urllib2_fork.py", line 1118, in do_open 
    raise URLError(err) 
URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond> 
+1

它是一个导致它引发此错误的特定URL? 'URLError'看起来像是超时错误。如果结果不是致命的,请使用'try..except'来处理这个错误。 –

+0

把请求的代码部分放在这里。 –

+0

您是否在所有系统上使用相同的python和机械化版本? – alecxe

回答

5

我严重怀疑,问题是连接到您的系统。要解决这个问题,我会建议:

  1. 检查机械化版本。旧版本可能会以不同方式处理请求。
  2. 调查set_handle_robotsaddheaders。问题可能与每个IP的请求太多有关。 (我怀疑这是真正的问题。)
  3. 检查错误处理。就像上面的注释中所描述的那样,您应该添加适当的错误处理。

如果上述解决方案均不起作用,请提供导致错误的代码。

1

从错误我推断您尝试连接到的服务器不允许您的连接。

尝试使用telnet仔细检查,你可以连接到URL/IP:PORT您要求:

telnet <ip> <port> 

PS:就在情况下,不要使用Ping你检查你不去测试连通性港口。