I perform the following code:
import urllib.request
from datetime import datetime
start = datetime.now()
user_agent = 'First Lastname [email protected]' # SEC uses this format as header.
url = 'https://data.sec.gov/submissions/CIK0000320193.json'
headers={'User-Agent':user_agent,}
request=urllib.request.Request(url,None,headers)
response = urllib.request.urlopen(request)
data = response.read()
print(datetime.now() - start)
It took me 0:02:33.646154
2.5 minutes.
That doesn't make sense to me because I can open the link with browser in less than a second.
Why does the code so slow? How could I make it faster?
Thank you for any suggestions.
CodePudding user response:
I ran the exact code you provided and it returned in 0:00:00.515504
seconds.
Here are 3 reasons for why it might take you so long until it is returned.
- Your computer is incredibly slow.
- Your internet connection is slow/unstable.
- Maybe
https://data.sec.gov
deliberatly takes so long to return to you because you ran the code a lot of times and is giving you some kind of cool-down.