You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用requests库发起带查询参数的HTTP GET请求失败求助

解决Python requests请求SSL证书验证失败的问题

你遇到的是SSL证书验证失败错误,原因是目标网站的SSL证书未被本地Python环境的CA证书库信任,导致请求被拦截。以下是两种解决方案:

方案1:临时绕过证书验证(仅测试用)

这种方法适合快速验证功能,但不建议在生产环境使用,会降低请求安全性:

  • 移除GET请求中多余的data=payload参数(GET请求不需要请求体,该参数无实际作用)
  • 在请求中添加verify=False参数,跳过证书验证
  • 可选:抑制requests抛出的不安全请求警告

修改后的完整代码:

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

# 抑制不安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

url = "https://busquedas.elperuano.pe/api/v1/elvis"

querystring = {"from_date":"01-01-1996","page":"0","scope":"false","to_date":"21-07-2023"}

headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Language": "es-ES,es;q=0.7",
    "Connection": "keep-alive",
    "Referer": "https://busquedas.elperuano.pe/",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "Sec-GPC": "1",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
    "sec-ch-ua": "^\\^Not/A",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "^\\^Windows^^"
}

# 发起请求,跳过证书验证
response = requests.request("GET", url, headers=headers, params=querystring, verify=False)

print(response.text)

方案2:配置信任的CA证书(生产环境推荐)

如果需要在生产环境使用,建议手动添加目标网站的CA证书到信任列表:

  1. 用浏览器访问https://busquedas.elperuano.pe,导出网站的CA证书(保存为PEM格式)
  2. 在请求中指定证书路径:
# 替换为你的证书文件实际路径
response = requests.request("GET", url, headers=headers, params=querystring, verify="/path/to/your/certificate.pem")

内容的提问来源于stack exchange,提问作者Eduardo Arhuata

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 19:17:31