- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个讨厌的错误:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
response.begin()
File "/usr/lib/python3.5/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.5/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/home/ubuntu/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
response.begin()
File "/usr/lib/python3.5/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/script.py", line 44, in <module>
response_service_k = service_k_lib.service_kData(data, access_token, apifolder)
File "/home/ubuntu/script_lib.py", line 238, in service_kData
datarALL.extend(data.result())
File "/usr/lib/python3.5/concurrent/futures/_base.py", line 398, in result
return self.__get_result()
File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/ubuntu/script_lib.py", line 129, in getdata3
responsedata = requests.get(url, data=data, headers=hed, verify=False)
File "/home/ubuntu/.local/lib/python3.5/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/home/ubuntu/.local/lib/python3.5/site-packages/requests/adapters.py", line 495, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
根据这个answer我的问题的解决方案是放置:time.sleep(0.01)
策略性地在我的代码中。我明白了,但我不确定我是否知道我的代码中它的正确位置:
这是来自 script.py
的相关代码部分:
result= []
with ThreadPoolExecutor(max_workers=num_of_pages) as executor:
futh = [(executor.submit(self.getdata3, page, hed, data, apifolder,additional)) for page in pages]
for data in as_completed(futh):
result.extend(data.result())
print ("Finished generateing data.")
return result
这是 getdata3
函数的相关代码部分:
def getdata3(...)
datarALL = []
responsedata = requests.get(url, data=data, headers=hed, verify=False)
if responsedata.status_code == 200: # 200 for successful call
responsedata = responsedata.text
jsondata = json.loads(responsedata)
if "results" in jsondata:
if jsondata["results"]:
datarALL.extend(jsondata["results"])
print ("{1} page {0} finished".format(page,str(datetime.now())))
return datarALL
一些信息:
我的代码生成页面。
为每个执行 getdata3 的页面创建线程(向 API 发出 GET 请求)
每个线程返回单个页面的结果。
“合并”结果。
我的问题:
将 time.sleep(0.01)
放在哪里才能避免这个错误?
最佳答案
您可能已经想到了这一点。无论如何,我在 for 循环中发出发布请求时遇到了类似的问题,该循环运行 400 次,每个循环运行两个请求和退出循环后的最后一个请求。我在发出 API 请求时发现服务器 (check_mk) 尚未准备好,仍在编译一些热点和服务数据。所以我在每个请求之前放置了 time.sleep()
并解决了问题。我不知道你多久提出一次请求,但我会这样尝试:
def getdata3(...)
datarALL = []
time.sleep(0.01)
responsedata = requests.get(url, data=data, headers=hed, verify=False)
if responsedata.status_code == 200: # 200 for successful call
responsedata = responsedata.text
jsondata = json.loads(responsedata)
if "results" in jsondata:
if jsondata["results"]:
datarALL.extend(jsondata["results"])
print ("{1} page {0} finished".format(page,str(datetime.now())))
return datarALL
关于python - requests.exceptions.ConnectionError : ('Connection aborted.' , ConnectionResetError(104, 'Connection reset by peer' )),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52051989/
我有一个关于在 Python3 中处理 ConnectionResetError 的问题。这通常发生在我使用 urllib.request.Request 函数时。我想知道如果我们遇到这样的错误是否可
我是 python 的新手。下面的函数给出了 imdb 中的电影和导演名称。它适用于单个链接。但是,当我为大量链接运行它时,它会出现 ConnectionResetError: [WinError 1
# -*- coding: UTF-8 -*- import urllib.request import re import os os.system("cls") url=input("Url Li
我是 Python 3 的新手,正在使用 asyncio。因此,我在以下服务器端代码中遇到了奇怪的行为: import asyncio @asyncio.coroutine def handle_cl
我正在尝试使用以下问题中的代码将文件上传到 S3 存储桶:https://stackoverflow.com/a/15087468/291372 。我正在使用 boto2 (boto3 有太多依赖项)
长话短说 我的问题很简单 - 在调用 self._sslobj.read(len, buffer) rows = (row for row in reader) File "/XXX/lib/pyth
使我的程序崩溃的异常如下: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versio
当使用 selenium 和 chromedriver 在 django 站点上运行测试时,我收到很多 ConnectionResetErrors。完整的错误输出包含在底部。请注意,即使如此,测试也能
我尝试使用 PUT REST Api 上传文件,但收到 ConnectionResetError 。我尝试过使用 urllib.request.Request()与 urllib.request.ur
我正在构建一个 Python 脚本,该脚本在我的数据库中搜索所有 URL,然后按照 URL 查找损坏的链接。该脚本在打开链接时遇到错误时需要使用异常处理来记录,但是它开始遇到错误,我完全无法为以下内容
编辑:澄清一下:它确实可以编译,但在流加载后几乎立即崩溃。 它确实连接正确。 所以,我已经尝试了很长时间来完成我的这个项目。我想做的是使用 cv2 通过套接字发送视频源。它通过 LAN 运行,而不是通
我有一个 Flask Rest api 应用程序,具有以下设置。 已安装的软件包 alembic==1.3.0 aniso8601==8.0.0 astroid==2.3.3 attrs==19.3.
客户端: data = b'\xff' * 1000000 ssock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) #context
我和你们中的许多人有类似的问题,但无法解决。我正在生成一个在我的 VirtualBox Linux 7.3 和 7.9 上运行良好的自执行文件,但是当我尝试在其他地方(在其他 Linux 服务器上)运
这个问题在这里已经有了答案: Selenium headless browser webdriver [Errno 104] Connection reset by peer (3 个答案) 关闭
我正在使用 python 3.6 并使用最新版本的 chromedriver,我尝试使用旧版本的 chromedriver,我遇到了同样的问题,重新启动了我的电脑,同样的问题。这是我运行以重现错误的代
通过stackoverflow搜索并发布这个问题,因为没有解决方案对我有用,我的问题可能与其他问题不同。 我正在编写一个脚本,它从rabbitMQ 队列中获取一篇文章并处理该文章以计算单词并从中提取关
我有这个讨厌的错误: Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.5/site-package
我正在使用 selenium 模块,但突然出现此错误 ConnectionResetError: [WinError 10054] An existing connection was forcibl
我有 socket 问题 import socket serverName = "herk-PC" serverPort = 12000 clientSocket = socket.socket(so
我是一名优秀的程序员,十分优秀!