首页 > 解决方案 > python http.client:如何在正文中使用 multipart/form-data 内容类型进行 POST 调用

问题描述

我正在尝试调用一个以 json 为内容的端点。

我试过这个

    def upload():

        connection = http.client.HTTPSConnection(self.url)
        headers = { 'Content-Type': 'multipart/form-data'}
        connection.request("POST", "/",body=json.dumps(self.myjson), headers)

我的json的内容是这样的

{"file": { "version":"2.0", "path":"my path", "test": "content"}}

问题是当我使用邮递员并直接上传文件时,它可以工作。但是当我尝试这部分代码时,我遇到了这个错误:

nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile] for property 'file[0]': no matching editors or conversion strategy found

我该如何解决这个问题?

标签: pythonpython-3.xpostmanmultipartform-data

解决方案


推荐阅读