使用 Python 请求从文件上传数据(如 curl 中的@file)

Upload data from file with Python requests (like @file in curl)

我正在尝试使用 bitbucket API - https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm8283193008 在 bitbucket 中设置用户头像。文档中的卷曲示例对我有用,但我不知道如何让我的 python 请求与给定端点一起工作。响应始终为 415,这意味着 "wrong content type"。除此之外,我相信,一切正常,看起来唯一的问题是 requests.post 方法中的 json 参数。我的问题是我应该在 json={'avatar': } 中写什么才能使它等于 @image.png in curl.

@furas 回答了我的问题。 curl.trillworks.com 是一个将 curl 转换为 python 的好网站。就我而言,我不应该使用 json={},而应该使用 file={filename, file_binary}