我在邮递员中运行了一个API,并且运行良好。这是代码:
import requests
url = 'https://sct.intutrack.com/api/prod/login'
payload = {}
headers = {}
response = requests.request('POST', url, headers = headers, data = payload, allow_redirects=False, timeout=undefined, allow_redirects=false)
print(response.text)
当我检查邮递员中的python代码时,它给了我
import requests
url = "https://sct.intutrack.com/api/prod/login"
payload = ""
headers = {
'Content-Type': "application/json",
'User-Agent': "PostmanRuntime/7.15.0",
'Accept': "*/*",
'Cache-Control': "no-cache",
'Postman-Token': "33e50c20-f264-4b65-8fc8-7016b3315134,8b5414b1-4b79-4749-91d7-80daa4d4ecbe",
'Host': "sct.intutrack.com",
'accept-encoding': "gzip, deflate",
'content-length': "",
'Connection': "keep-alive",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
我有一个API用户名和密码(我在“授权”中通过了该密码),但是在python代码中找不到相同的用户名和密码。如何更改它们?
Jupyter Notebook中的结果:
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>
答案 0 :(得分:-1)
您应该将包含用户名和密码的json字符串放入 在以下框中: 然后单击python中的代码,它将显示正确的代码,如下所示:
相同设置
payload = "{\"username\": \"\",\"password\": \"xxxxxx\",\"remeber\":0}"