在python上测试flaskapi时遇到错误403

2024-09-28 01:31:02 发布

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

我可以在Postman上测试这个文件,但是当我在Python上测试时,它失败了。我现在在一个网络代理后面工作,所以我已经指定了代理。你知道吗

这是我正在使用的一组代码:

# specify proxy
proxy = {'https':'https://username:password@01.2.345.6:1010', 
         'http':'http://username:password@01.2.345.6:1010'}

# specify content
header = {'Content-Type': 'application/json'}

# get input
testFile = open('test.json', 'r')
jsonInput = testFile.read()
requestJSON = json.loads(jsonInput)

# specify url
url = 'http://127.0.0.1:5000/test'

response = requests.post(url, json=requestJSON, proxies=proxy, headers=header)

当我检查状态码response时,得到的值是403。你知道吗


Tags: httpstestjsonhttpurl代理responseusername

热门问题