使用Python请求访问纳斯达克历史数据导致连接超时

vam*_*dur 2 python finance python-requests

我尝试运行这段 Python 代码(使用 requests 库)从 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)
Run Code Online (Sandbox Code Playgroud)

尽管能够通过 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))
Run Code Online (Sandbox Code Playgroud)

这是因为 NASDAQ.com 采取了反抓取措施,还是我在请求中遗漏了某些信息?任何解决问题的帮助将不胜感激。

小智 9

尝试添加这三个标头:

"Accept-Language":"en-US,en;q=0.9"
"Accept-Encoding":"gzip, deflate, br"
"User-Agent":"Java-http-client/"
Run Code Online (Sandbox Code Playgroud)