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

Curl调用Ryviu评论接口正常,Python Requests请求返回‘not found’

Curl调用Ryviu API正常,Python requests请求返回"not found"问题

我尝试调用Ryviu网站的API获取商品评论,终端执行curl命令能正常收到服务器响应,但用Python requests库调用相同API时返回{"msg":"not found"},求解决。

正常工作的Curl命令

curl 'https://app.ryviu.io/frontend/client/get-more-reviews?domain=tornado-fans.myshopify.com' \
  -H 'authority: app.ryviu.io' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'accept-language: en-US,en;q=0.9,hi;q=0.8,de;q=0.7,ur;q=0.6,pa;q=0.5,es;q=0.4' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -H 'dnt: 1' \
  -H 'origin: https://www.tornadofans.com' \
  -H 'referer: https://www.tornadofans.com/' \
  -H 'sec-ch-ua: "Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36' \
  --data-raw '{"handle":"tornado-24-high-velocity-metal-portable-tilt-blower-drum-fan-yellow-8540-cfm-ul","product_id":7245574144198,"page":2,"type":"load-more","order":"late","filter":"all","feature":false,"domain":"tornado-fans.myshopify.com","platform":"shopify"}' \
  --compressed

失败的Python requests代码

import requests

url = "https://app.ryviu.io/frontend/client/get-more-reviews?domain=tornado-fans.myshopify.com"

payload='%7B%22handle%22%3A%22tornado-24-high-velocity-metal-portable-tilt-blower-drum-fan-yellow-8540-cfm-ul%22%2C%22product_id%22%3A7245574144198%2C%22page%22%3A2%2C%22type%22%3A%22load-more%22%2C%22order%22%3A%22late%22%2C%22filter%22%3A%22all%22%2C%22feature%22%3Afalse%2C%22domain%22%3A%22tornado-fans.myshopify.com%22%2C%22platform%22%3A%22shopify%22%7D='
headers = {
  'authority': 'app.ryviu.io',
  'accept': 'application/json, text/plain, */*',
  'accept-language': 'en-US,en;q=0.9,hi;q=0.8,de;q=0.7,ur;q=0.6,pa;q=0.5,es;q=0.4',
  'content-type': 'application/x-www-form-urlencoded',
  'dnt': '1',
  'origin': 'https://www.tornadofans.com',
  'referer': 'https://www.tornadofans.com/',
  'sec-ch-ua': "Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110"',
  'sec-ch-ua-mobile': '?0',
  'sec-ch-ua-platform': "macOS"',
  'sec-fetch-dest': 'empty',
  'sec-fetch-mode': 'cors',
  'sec-fetch-site': 'cross-site',
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Python请求返回结果

{"msg":"not found"}

问题分析与解决方法

核心问题1:Payload格式错误

Python代码中的payload末尾多了一个=符号,且不需要手动进行URL编码。Curl的--data-raw是直接发送原始JSON字符串,而你手动编码后添加的多余=导致服务器无法正确解析请求体。

核心问题2:Headers语法错误

Headers中的sec-ch-ua和sec-ch-ua-platform值没有正确用单引号包裹,会导致实际发送的Header内容异常,服务器可能因此拒绝请求。

修正后的Python代码

import requests

url = "https://app.ryviu.io/frontend/client/get-more-reviews?domain=tornado-fans.myshopify.com"

# 直接使用原始JSON字符串作为payload,requests会自动处理编码
payload = '{"handle":"tornado-24-high-velocity-metal-portable-tilt-blower-drum-fan-yellow-8540-cfm-ul","product_id":7245574144198,"page":2,"type":"load-more","order":"late","filter":"all","feature":false,"domain":"tornado-fans.myshopify.com","platform":"shopify"}'
headers = {
    'authority': 'app.ryviu.io',
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'en-US,en;q=0.9,hi;q=0.8,de;q=0.7,ur;q=0.6,pa;q=0.5,es;q=0.4',
    'content-type': 'application/x-www-form-urlencoded',
    'dnt': '1',
    'origin': 'https://www.tornadofans.com',
    'referer': 'https://www.tornadofans.com/',
    'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'cross-site',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'
}

response = requests.post(url, headers=headers, data=payload)
print(response.text)

额外优化建议

可以直接传入Python字典作为payload,requests会自动编码为application/x-www-form-urlencoded格式,代码更易维护:

payload = {
    "handle": "tornado-24-high-velocity-metal-portable-tilt-blower-drum-fan-yellow-8540-cfm-ul",
    "product_id": 7245574144198,
    "page": 2,
    "type": "load-more",
    "order": "late",
    "filter": "all",
    "feature": False,
    "domain": "tornado-fans.myshopify.com",
    "platform": "shopify"
}
# 直接传data=payload即可,无需手动构造字符串
response = requests.post(url, headers=headers, data=payload)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 03:15:02