python - 为什么 request.get() 在 python 中给我一个错误?
问题描述
import requests
url="https://beta.nseindia.com/api/option-chain-indices?symbol=NIFTY"
requests.get(url)
我正在使用请求,但它给了我一个超时错误..但是当我在浏览器中打开相同的链接时它工作正常
解决方案
尝试使用一些用户代理字符串标头:
import requests
url="https://beta.nseindia.com/api/option-chain-indices?symbol=NIFTY"
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)
>>> response
<Response [200]>
>>>
beta.nseindia.com/
有一个阻止来自机器人的请求的策略。
推荐阅读
- powershell - VSCode Powershell 终端 - 截断行
- r - 用 R 中的组中的非 NA 字符替换一组值的 NA
- c# - 标签未出现在 xamarin 应用 android 设备上
- javascript - 在axios中使用get请求下载文件
- c++ - 获取 std::array 的大小作为 r 值
- svg - 使用带有 SVG 的框架无法使其增长
- python - 是否可以实现一个上下文管理器来处理向 cuda 的张量传输
- node.js - 为什么我的 getServerSideProps 在 Vercel 上返回 404,但在 localhost 上却没有
- mysql - 使用 IN 使用数百个 WHERE 子句提高查询性能
- typescript - 在 Typescript 类成员中进行 Axios 调用