【发布时间】:2020-05-15 22:50:36
【问题描述】:
我正在尝试检查链接是否损坏。为此,我从带有 while 循环的字典列表中发送一个元素(链接),并且我正在使用 urllib.request。目标是仅从列表中删除断开的链接。列表包含来自https://jamanetwork.com/ 的不同文章的链接,我希望能够下载现有的文章。
但是我收到 ConnectionResetError: [Errno 104] Connection reset by peer。 当我尝试测试来自https://jamanetwork.com/ 的链接以及https://jamanetwork.com/ 上的每个页面时,我只会收到该错误,但代码似乎适用于其他网站。
我的问题是:我在这里遗漏了什么还是服务器端的问题?
这是我的代码(python3):
import urllib.request
i = 0
while i < (len(dicts)):
url = dicts[i]['link']
try:
with urllib.request.urlopen(url) as f:
status = f.getcode()
i += 1
except:
del dicts[i]
这是一个回溯:
https://jamanetwork.com/
---------------------------------------------------------------------------
ConnectionResetError Traceback (most recent call last)
<ipython-input-59-8d93b45dbd14> in <module>()
22 print(url)
23
---> 24 with urllib.request.urlopen("https://jamanetwork.com/") as f:
25 status = f.getcode()
26 print(status)
12 frames
/usr/lib/python3.6/ssl.py in read(self, len, buffer)
629 """
630 if buffer is not None:
--> 631 v = self._sslobj.read(len, buffer)
632 else:
633 v = self._sslobj.read(len)
ConnectionResetError: [Errno 104] Connection reset by peer
任何建议都非常感谢,谢谢!
【问题讨论】:
-
你有网络问题吗?
-
不,我也使用 google colab,不知道这是否重要
标签: python python-3.x python-requests