python请求中这个凭证站点的正确头/负载是什么?

2024-07-04 08:15:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在设置一个python脚本,检查凭证代码是否仍然有效。 (站点为:“https://www.lieferando.de/checkVoucher.php”)

我在Postman和ARC中工作,但是我不能让它处理Python请求。我也试过邮递员的create code函数,但仍然不起作用。你知道吗


url = "https://www.lieferando.de/checkVoucher.php"

payload = {'vouchercode': "TRF5RCF6VRLZ7552"}
headers = {
    'vouchercode': "TRF5RCF6VRLZ7552",
    'Content-Type': "application/x-www-form-urlencoded",
    'User-Agent': "PostmanRuntime/7.11.0",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Postman-Token': "143f10f9-4bfc-4bfe-9cb9-ae4159118c7c,14eebeb3-f79b-4dea-9279-328e5dad1850",
    'Host': "www.lieferando.de",
    'cookie': "visid_incap_1716123=fad1eRraQbSyEro92B7ouuB0y1wAAAAAQUIPAAAAAAAhvXPqviZx2wjoycs1g4Fc; incap_ses_727_1716123=+tNFCxebHDoMdSkWn9MWCljCy1wAAAAAzwDNwJi0+rHL/bgMW1zj3Q==; incap_ses_184_1716123=geD7AxnPrHLB4TighrSNAnuFy1wAAAAAFTCb2kBj03wyR2BVXlobyg==; incap_ses_876_1716123=tlZZBSxfnSPJPB4gFi4oDI6Ly1wAAAAAWxnq9RAJRBvFTuNF7EhDEw==; incap_ses_730_1716123=JW8oXiBsrk8SYz8T/3shCmCRy1wAAAAApG2tibhMTuqnZBYjb+JDGg==; incap_ses_536_1716123=GY3ddNoWphYa0bcoG0JwB+mXy1wAAAAAxqvjmrYrd4ZqhbHGH418eQ==; nlbi_1716123=4oBPV9c8liHrbOgrX9BzAQAAAADFGnUou8G0vVD66E07GFpV; incap_ses_246_1716123=Oka1Xjj8WAEkqd1TwPdpA/qly1wAAAAAWjqXqiPrP3pj1mpDS572Lg==; incap_ses_108_1716123=madBJ0JEly173VQl8LN/Ab+1y1wAAAAAzTICVw2c/Vk5RibweBnRHQ==; incap_ses_877_1716123=atGOOty1yBkTqVcPrLsrDG+KzFwAAAAAtCkMsl02gWsI0TCmJVWhjQ==; PHPSESSID=j812qmhlang0kvh8rfdulhkm56",
    'accept-encoding': "gzip, deflate",
    'content-length': "1376",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

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

print(response.text)

服务器应响应

{"basketResponse":null,"status":"error","value":"Alle Gutscheine mit diesem Gutscheincode wurden bereits verwendet. Es sind keine Gutscheine verf\u00fcgbar und somit ist der Code nicht mehr g\u00fcltig."

但回应是

{"basketResponse":null,"status":"error","value":"Bitte gib den Gutscheincode ein","markfields":["ivouchercode"]}

Tags: httpsurlcachewwwdepostmanheaderspayload
1条回答
网友
1楼 · 发布于 2024-07-04 08:15:57

所以你的代码有几个问题:

  1. 您应该将payload作为JSON字符串发送(因此将data=替换为json=

  2. 您使用的headers不正确

  3. 您应该在POST请求中包含cookies(您可以使用requests.session()自动完成)

总之,您的代码应该如下所示:

import requests

session = requests.session()

url = "https://www.lieferando.de/checkVoucher.php"

headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:66.0) Gecko/20100101 Firefox/66.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "DNT": "1", "Connection": "close", "Upgrade-Insecure-Requests": "1"}
session.request("GET", "https://www.lieferando.de/bestellung-abschliessen-miran-pizza-doener", headers=headers)

payload = {'vouchercode': "TRF5RCF6VRLZ7552"}
response = session.request("POST", url, json=payload, headers=headers)

print(response.json())

(附言: response.json()response转换为JSON字符串,这使其更易于使用。如果不需要,您可以改用.text

希望这有帮助

相关问题 更多 >

    热门问题