最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Are `curl` and programmatic requests not same? - Stack Overflow

programmeradmin2浏览0评论

I checked response from Python requests.get() and curl both gave the same response.

# Python
headers = {
    "User-Agent": "curl/8.9.1",
    "Accept-Encoding": "*",
    "Accept": "*/*"
}
cookies = {
    "ndus": "ndus_DummyData",
    "ndut_fmt": "ndut_fmt_DummyData",
    "TSID": "TSID_DummyData"
}
res = requests.get('', cookies=cookies, allow_redirects=True, headers=headers)
print(res.text)

# Response
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "*",
    "Cookie": "ndus=ndus_DummyData; ndut_fmt=ndut_fmt_DummyData; TSID=TSID_DummyData",
    "Host": "httpbin",
    "User-Agent": "curl/8.9.1",
    "X-Amzn-Trace-Id": "Root=1-abc123456798"
  },
  "origin": "XXX.XX.XX.XXX",
  "url": ";
}
# Curl
curl --header "Accept-Encoding: *" -b "ndus=ndus_DummyData; ndut_fmt=ndut_fmt_DummyData; TSID=TSID_DummyData" ";

# Response
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "*",
    "Cookie": "TSID=TSID_DummyData; ndut_fmt=ndut_fmt_DummyData; ndus=ndus_DummyData",
    "Host": "httpbin",
    "User-Agent": "curl/8.9.1",
    "X-Amzn-Trace-Id": "Root=1-abc123456799"
  },
  "origin": "XXX.XX.XX.XXX",
  "url": ";
}

But with same configurations (cookies and headers) when I hit this link (;web=1&channel=dubox&clienttype=0&jsToken=XXXX&dp-logid=XXXX&page=1&num=20&by=name&order=asc&site_referer=&shorturl=XXXX&root=1) (some secrets data are masked) it gives different response in Python ({"errmsg":"need verify","request_id":4420565811,"errno":400141}) and different in curl (successful data as expected).

I also checked with NodeJS fetch, behavior is same as Python requests.

How can I fix this behavior. Why there is difference in response for same request from curl and programmatic requests? Can anyone please help?

发布评论

评论列表(0)

  1. 暂无评论