我试图使一个API调用从ryviu网站获得评论。
如果我在终端中执行下面的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请求进行相同的API调用,请求永远不会成功。我使用的代码如下:
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”}作为响应。
救命!
我想知道为什么curl可以工作,但没有python库可以工作。
我什么都试过了,我能。
1条答案
按热度按时间vulvrdjw1#
问题可能是您的有效负载编码不正确。使用第一个例子中的dictionnary,并使用
json=
而不是data=
来为POST请求提供有效负载(这里有更多内容),我得到了一个肯定的结果:字符串