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

标签 python python-requests finance

我尝试运行这段 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/

相关文章:

r - 在 Ibrokers 上使用 R 获取 EUR.USD 历史数据时出错

finance - 对于金融部门的人员来说,数据存储问题

python - VS Code 终端中的光标错误

python - python 2.7 上的 pygame 在 macOS Mojave v10.14.6 上使用 PYGAME_WINDOW.screen.fill

python - Django Tastypie 添加 Content-Length header

python - 如何将带撇号的字符串对象传递给 POST 调用

Python 请求库 pre_request 钩子(Hook)

python - 在nltk bigraph的python中转换计数器列表

python - 如何使用 Python Requests 库或 PyCurl 使用以前的 cookie 进行 POST?

r - 如何使用R包的MACD函数?