post在postman上工作,但在python中不工作

zc0qhyus  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(353)

我正在用python运行post进行多部分上传,它在postman中运行良好,我在2分钟后(预期行为)被202接受。现在,我复制了postman for python的代码,并尝试在python中执行,但它给出了404。以下是postman生成的python代码:

import requests

url = "https://mycompany.com:8443/gateway/saap/environments/q9b-resources"

payload={}
files=[
  ('request',('test.yaml',open('/Users/test/test.yaml','rb'),'application/octet-stream'))
]

headers = {
  'Content-Type': 'multipart/form-data',
  'Authorization': 'token'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files,verify="mycert.ca")

print('r')

# print(request)

print(response.text)
print(' done ')
print(response.status_code)
print(response.text)

输出:
完成404
为什么会出现这种行为?除了在请求中添加了cert之外,我并没有做任何更改,这很好,因为如果不添加cert,我会得到ssl验证错误。
还有另外一个api,它执行普通的post来生成令牌,它在postman中工作得很好,但为什么上面的代码给出404?
我可以打:-https://mycompany.com:8443/gateway/security/tokens 响应json来自于此。
但问题的url是:https://mycompany.com:8443/gateway/saap/environments/q9b-资源
如果我能从 Postman 那里打,为什么不能从python

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题