I am trying to check if a link is broken or not. For that I am sending an element (a link) from a list of dictionaries with a while loop and I am using urllib.request. The goal is to remove only broken links from the list. List contains links to different articles from https://jamanetwork.com/ and I want to be able to download articles that exist.
However I am getting a ConnectionResetError: [Errno 104] Connection reset by peer. I only get that error when I am trying to test links from https://jamanetwork.com/, and every page on https://jamanetwork.com/, but code seems to work fine for other websites.
My question is: am I missing something here or is it server side issue?
Here is my code (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]
Here is a traceback:
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
Any suggestions are appreciated, thanks!