Python请求在Postman上工作,但不在本地机器上

34gzjxbg  于 2023-08-05  发布在  Postman
关注(0)|答案(1)|浏览(169)

我刮使用 Postman ,我已经找到了我需要什么数据,我只需要它在本地工作。虽然它可以在postman和kaggle中工作,但不能在本地机器中工作,也不能在colab中工作。代码如下:`

import requests

url = "https://apisae1.phdvasia.com/v1/product-hut-fe/localizations?order_type=C&disposition=C&limit=4"

payload = {}
headers = {
  'authority': 'apisae1.phdvasia.com',
  'accept': 'application/json, text/plain, */*',
  'accept-language': 'en-US,en;q=0.9',
  'client': '57950680-0208-4703-9e0b-c5a8cc45cf42',
  'lang': 'pt',
  'origin': 'https://www.pizzahut.com.br',
  'referer': 'https://www.pizzahut.com.br/',
  'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
  'sec-ch-ua-mobile': '?0',
  'sec-ch-ua-platform': '"Windows"',
  'sec-fetch-dest': 'empty',
  'sec-fetch-mode': 'cors',
  'sec-fetch-site': 'cross-site',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 OPR/99.0.0.0',
  'Cookie': 'ak_bmsc=CA52AD92D65BE36761FAC7C181F253D0~000000000000000000000000000000~YAAQxGvcF7RDj0SJAQAALPEpSRSGE7kXTAwqrRr6W7FKHAmAiIZLed4usMa8hURw56blJZSho5ANdgoKbhEiJCGu8lFXst2L2uWHVaoNXi3QZgkcGHgYmHvWNw94pK9aoh4zr9YvHaeMFRd5Xr01mSDpSfjtx7PwGydeGkLcRo+2PX6xlXM9UPSDal59DPOjkM0LclJgl0s3FOumelzJrL5f73VPNQBEmh9Ek+XInsBiO5z6x118opcFaDNoRGAW/8rnaYJgQNF/t7WgfddKr7VA6Dif7s6mA0kxiUYlXpjQLuaFvCNc++RO6+fqm0fPz8bz8BQPKg9OIjzDPSdXUrRMkpQhdmImyzNDv/v2MePK8H2BYZnjh1JK0Kuw; bm_sv=FBC11E925F19B3C0A6BA6708D42A3D3A~YAAQxGvcF8yxkESJAQAAFkxASRT933k/B3sEomiSPBAzN4AEskTpDt7ilDa1EZwRgSq0vPW3eeF1pcmF8mfeEzeUTd9M9cLkVh3FoENhHyaorUh9yPYxu06HHCdXltInBWkY5jXsNa18804DF6tVDieU0ZZd4cKm8o1AMB1luUPGsLPJewgPVQWNWMeKAz6PyZVo+qAcZPW67ACmEzr4J+SONmXPAiPlK0jn77bU8PEOWAukDLbeO6BzwGFm6a4ESjr3~1'
}

response = requests.request("GET", url, headers=headers, data=payload, allow_redirects=False)

print(response.text)

字符串
我尝试将用户代理更改为随机的,甚至是我正在使用的浏览器的当前版本,并在其他云服务上尝试。它在kaggle上工作,但在colaband本地机器上不工作。PLs帮助

bhmjp9jg

bhmjp9jg1#

您需要的唯一头值是客户端。

import requests
import json # only used for presentation

url = "https://apisae1.phdvasia.com/v1/product-hut-fe/localizations?order_type=C&disposition=C&limit=4"

headers = {
    'client': '57950680-0208-4703-9e0b-c5a8cc45cf42'
}

with requests.get(url, headers=headers) as response:
    response.raise_for_status()
    print(json.dumps(response.json(), indent=2))

字符串
如果没有客户端头(或无效的客户端),您将得到HTTP400

相关问题