简体   繁体   中英

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

I'm trying to set user's avatar in bitbucket using bitbucket API - https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm8283193008 . Curl example from docs works for me, but I have no idea how to get my python requests working with given endpoint. The response is always 415, which means "wrong content type". Besides that, I believe, everything works fine, looks like the only problem is json parameter in requests.post method. My question is what should I write in json={'avatar': } to make it equal to @image.png in curl.

@furas answered my question. curl.trillworks.com is a great website to convert curl to python. In my case I shouldn't have used json={}, instead I should've used file={filename, file_binary}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM