请求-如何使用请求库帖子调用发送图像和json

时间:2019-11-17 06:52:16

标签: python-3.x python-requests

我无法使用请求python进行发布通话。正在收到415回应。下面是我的示例代码。

import json
import requests

payload = {"projectID": 44100,"projectName": "AutomationTest","clientName": "Automation","awsRegion": "Automation_Test","environment": "Dev","active": True,"clustered": False,"measurementTypesJson": "[Automation]"}
files = {
 'projectInfo': (None, json.dumps(payload), 'application/json'),
 'logo': (open('tiff-icon-40517.jpeg', 'rb'), 'multipart/form-data')
}
url = "passing my url here"

headers = { 
'Authorization': "passing auth token here"
}

print(files)
response = requests.request("POST", url, data=files, headers=headers)
print(response)

响应-415

我也尝试过将徽标/图像类型更改为image / jpeg和application / octet-stream,但是没有用

0 个答案:

没有答案