【问题标题】:Mechanize [Errno 10054] An existing connection was forcibly closed by the remote hostMechanize [Errno 10054] 现有连接被远程主机强行关闭
【发布时间】:2012-08-13 05:40:02
【问题描述】:

我浏览了整个互联网,但找不到解决此错误的方法。有谁知道怎么回事?

代码:

for index in range(len(sections)):      
    br.select_form(name="win1")
    post_url, post_data, headers =  br.form.click_request_data()
    post_data = post_data.replace("ICAction=None", "ICAction=DERIVED_CLSRCH_SSR_CLASSNAME_LONG$"+str(index))
    r = br.open(post_url, post_data) ##ERROR ON THIS LINE
    html = r.read()

    if index < range(len(sections)):
        br.select_form(name="win1")
        post_url, post_data, headers =  br.form.click_request_data()
        post_data = post_data.replace("ICAction=None", "ICAction=CLASS_SRCH_WRK2_SSR_PB_BACK")
        r = br.open(post_url, post_data)
        html = r.read()

错误日志

[Sun Aug 12 22:28:04 2012] [error] Traceback (most recent call last):
[Sun Aug 12 22:28:04 2012] [error]   File "C:/wamp/www/python/scrape.py", line 131, in application
[Sun Aug 12 22:28:04 2012] [error]     r = br.open(post_url, post_data)
[Sun Aug 12 22:28:04 2012] [error]   File "build\\bdist.win-amd64\\egg\\mechanize\\_mechanize.py", line 203, in open
[Sun Aug 12 22:28:04 2012] [error]     return self._mech_open(url, data, timeout=timeout)
[Sun Aug 12 22:28:04 2012] [error]   File "build\\bdist.win-amd64\\egg\\mechanize\\_mechanize.py", line 230, in _mech_open
[Sun Aug 12 22:28:04 2012] [error]     response = UserAgentBase.open(self, request, data)
[Sun Aug 12 22:28:04 2012] [error]   File "build\\bdist.win-amd64\\egg\\mechanize\\_opener.py", line 193, in open
[Sun Aug 12 22:28:04 2012] [error]     response = urlopen(self, req, data)
[Sun Aug 12 22:28:04 2012] [error]   File "build\\bdist.win-amd64\\egg\\mechanize\\_urllib2_fork.py", line 344, in _open
[Sun Aug 12 22:28:04 2012] [error]     '_open', req)
[Sun Aug 12 22:28:04 2012] [error]   File "build\\bdist.win-amd64\\egg\\mechanize\\_urllib2_fork.py", line 332, in _call_chain
[Sun Aug 12 22:28:04 2012] [error]     result = func(*args)
[Sun Aug 12 22:28:04 2012] [error]   File "build\\bdist.win-amd64\\egg\\mechanize\\_urllib2_fork.py", line 1170, in https_open
[Sun Aug 12 22:28:04 2012] [error]     return self.do_open(conn_factory, req)
[Sun Aug 12 22:28:04 2012] [error]   File "build\\bdist.win-amd64\\egg\\mechanize\\_urllib2_fork.py", line 1118, in do_open
[Sun Aug 12 22:28:04 2012] [error]     raise URLError(err)
[Sun Aug 12 22:28:04 2012] [error] URLError: <urlopen error [Errno 10054] An existing connection was forcibly closed by the remote host>

【问题讨论】:

  • 服务器发生了一些事情,它可能已经崩溃或意外关闭。
  • 当我在浏览器上复制操作时工作正常

标签: python mechanize


【解决方案1】:

想通了,帖子数据很大,我猜它弄乱了请求。我把它修整了,现在可以正常工作了。

【讨论】:

    【解决方案2】:

    仔细检查您的协议支持,当我尝试连接到禁用 TLS1.0 的服务器时,我遇到了这个错误(python 2.7、windows 2008R2 server/IIS 7、windows 7 客户端),一旦我启用了问题就消失了.

    【讨论】:

      猜你喜欢
      • 2012-02-07
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多