Api 无法使用参数python请求通过文件发布图像

Api 无法使用参数python请求通过文件发布图像,api,http,python-requests,Api,Http,Python Requests,我正在尝试将带有请求模块的映像从本地客户端发布到服务(tillhub.com)。因为用于发布图像的api文档缺少(至少对我来说)一些重要方面,所以我尝试使用Google Chrome开发工具来找出必要的参数。当我直接从仪表板上传图像时,我可以看到标题使用了以下参数: 此外,我可以看到将要传递以下表单数据: 我试图用以下代码片段模拟来自本地客户端的请求: import requests headers = {'content-type': 'multipart/form-data; bou

我正在尝试将带有请求模块的映像从本地客户端发布到服务(tillhub.com)。因为用于发布图像的api文档缺少(至少对我来说)一些重要方面,所以我尝试使用Google Chrome开发工具来找出必要的参数。当我直接从仪表板上传图像时,我可以看到标题使用了以下参数:

此外,我可以看到将要传递以下表单数据:

我试图用以下代码片段模拟来自本地客户端的请求:

import requests

headers = 
{'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryOVDXaA33W3zKicwR',
 'cache-control': 'no-cache',
 'Authorization': 'Bearer .......',
 'accept': 'application/json, text/plain, */*'}

files= {'image': ("demo.jpg",open("demo.jpg", "rb"),'image/jpeg')}

requests.post(url=url,files=files, headers=headers).json()
导致

{'status': 400,
 'msg': 'Unexpected token - in JSON at position 0',
 'request': {'host': 'api.tillhub.com',
  'id': '946f956c-efcf-48e8-aec8-44e16b118a4e'}}
根据它们的特性,我可以看出它们仅用于内容类型“image/jpeg”:

 async create (query: ImagesQuery, payload: FormData): Promise<ImagesResponse> {
    const uri = this.uriHelper.generateBaseUri(`/${query.subsystem}/${query.prefix}`)
    try {
      const response = await this.http
        .getClient()
        .post(uri, payload, { headers: { 'Content-Type': 'image/jpeg' } })
async create(查询:ImagesQuery,负载:FormData):Promise{
常量uri=this.uriHelper.generateBaeseuri(`/${query.subsystem}/${query.prefix}`)
试一试{
const response=等待this.http
.getClient()
.post(uri,有效负载,{headers:{'Content Type':'image/jpeg'}})

我是不是做错了什么事?如果您能提供帮助,我将不胜感激。

我在玩您的代码块。读完本文后,我删除了
内容类型

这对我很有效。你能试试这个吗

import requests

headers ={'Authorization': 'Bearer ey......eU','cache-control': 'no-cache'}
files=dict(image=('demo.jpg', open("demo.jpg", "rb"),'image/jpeg'))

requests.post(url=url,files=files, headers=headers).json()