gpt4 book ai didi

Python Rest API POST 图像

转载 作者:行者123 更新时间:2023-12-01 08:32:05 24 4
gpt4 key购买 nike

下面是我的代码。我正在尝试使用 python 和 REST API 进行 POST 操作。我有一张图片想要发布。我收到错误消息:

"'code': 'BadRequest', 'message': "Could not process incoming request: 'Missing content-type boundary.'. Please ensure that it is well-formed"

我哪里出错了?

import requests
headers = {
'accept': 'application/json',
'Content-Type': 'multipart/form-data',
#'boundary':'---BOUNDRY'
}
params = (
('returnFaceId', 'true'),
('returnFaceLandmarks', 'true'),
)
files = {
'form': (open('image.jpg', 'rb'),'image/jpg'),
}
response = requests.post('http://localhost:5000/face/v1.0/detect', headers=headers, params=params, files=files)
print (response.json())

最佳答案

[multipart data POST using python requests: no multipart boundary was found

上面的链接很有帮助。我删除了显式 header 和参数,它起作用了。

import requests

files = {
'form': ('images.jpg',open('images.jpg', 'rb'),'image/jpg'),
}

response = requests.post('http://localhost:5000/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false', files=files)
print(response.json())

关于Python Rest API POST 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53865934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com