使用python在Post请求中发送令牌

2024-06-13 18:25:16 发布

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

我正在尝试用python发出post请求。我已经在postman中测试了这个请求,它可以工作,但是当我尝试在python3.6脚本中运行它时,我得到了一个403 invalid token错误。有什么我不知道的吗?你知道吗

邮递员给我的现行代码如下

import requests

url = "https://www.deviantart.com/dapi/v1/browse/thumbs"

querystring = {"iid":"598m980bb6e26e5be0a33d4a88ed1c570026-jshtsqc2-1.21","mp":"5"}

payload = ""
headers = {
    'origin': "https://www.deviantart.com",
    'user-agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36",
    'content-type': "application/x-www-form-urlencoded",
    'accept': "*/*",
    'cache-control': "no-cache",
    'postman-token': "cd95e1a8-2203-eaaf-91ee-4cf56ee41875"
    }

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

print(response.text)

这个请求可以在我的浏览器和postman应用程序中工作,但不能在python中工作


Tags: https脚本comtokenurlcacheresponsewww