我尝试运行这段 Python 代码(使用请求库)从 NASDAQ.com 检索特斯拉一年的历史市场数据
dataURL = https://www.nasdaq.com/api/v1/historical/TSLA/stocks/2019-05-22/2020-05-21
quotesReq = requests.get(dataURL, allow_redirects = True)
尽管能够通过 Web 浏览器访问 URL 并下载预期的“.csv”文件,但我的 Python 代码会产生超时错误。
requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))
这是因为 NASDAQ.com 采取了反抓取措施,还是我在请求中遗漏了一些信息?任何解决此问题的帮助将不胜感激。
最佳答案
尝试添加这三个 header :
"Accept-Language":"en-US,en;q=0.9"
"Accept-Encoding":"gzip, deflate, br"
"User-Agent":"Java-http-client/"
关于python - 使用 Python 请求访问纳斯达克历史数据导致连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61943209/