python - http.client.RemoteDisconnected:当函数调用自身时,远程结束关闭连接而没有响应
问题描述
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 517, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 534, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1375, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1350, in do_open
r = h.getresponse()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1349, in getresponse
response.begin()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 316, in begin
version, status, reason = self._read_status()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 285, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
我正在做类似的事情:
def check_proxy(proxy_ip):
result = urllib.request.urlopen(url,proxy_ip)
if result == 'good': #Let's say if the proxy works we can get a 'good' result
return proxy_ip
else: #'bad' result
check_proxy(another_proxy_ip)
这是为了检查代理。我希望它通过调用自己来继续尝试,直到它得到一个“好”的代理。但是当结果“不好”并且它尝试再次执行 urlopen 时,我遇到了这个错误。
解决方案
推荐阅读
- robotframework - 在机器人脚本中导入关键字部分
- python - Window not opening inPyQT5 GUI
- docker - 将 docker-compose windows 容器暴露给 windows 主机网络
- mongodb - 集合名称上的MongoDB别名?
- excel - 有什么建议可以加快此代码或使其更高效(VBA Excel)?
- java - Spring Data/SQL Query 按集合查找所有匹配项
- python-3.x - 如何在 Python 中运行代码之前添加延迟
- xml - 如何进行休息调用并将 xml 响应存储在 XSLT 中的变量中?
- python - 基于区域合并区域
- linux - 如何在dockerfile的后台运行命令?