python - Mechanize [Errno 10054] 现有连接被远程主机强行关闭

标签 python mechanize

我在网上找遍了,但我找不到解决这个错误的方法。有人知道这是怎么回事吗?

代码:

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>

最佳答案

弄明白了,post 数据很大,我猜它弄乱了请求。我修剪了它,现在工作正常。

关于python - Mechanize [Errno 10054] 现有连接被远程主机强行关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11928697/

相关文章:

python - 直方图上的瑞利分布曲线

python - 将函数从 Python 转换为 C

python - 连接拒绝 PythonAnywhere 上的 Twitter API

ruby-on-rails - 如何使用带有 ruby​​ 的 Mechanize 循环创建日志文件

html - 有没有办法用 Mechanize 处理动态加载的内容?

ruby - 如何使用 Mechanize 浏览每个链接?

python - 在 map 上绘制洋流数据 : Too many value to unpack error

python - Pytest 使用函数进行参数化测试

python - 如何使用 Mechanize 填写搜索表单并返回结果?

ruby - 如何在 Mechanize 中获取重定向日志?