Python api 发布请求

时间:2020-12-20 15:08:13

标签: python api python-requests

我想将此代码转换为使用 python3 并使用 python-requests。 请帮帮我

import unirest
response = unirest.post("https://api.pixhost.to/images",
headers={
"Content-Type": "multipart/form-data; charset=utf-8",
"Accept": "application/json"
},
params={
"img": open("image.jpg", mode="r"),
"content_type": "0",
"max_th_size": "420"
}
)
      

参考这里是文档 https://pixhost.to/api/index.html?python#images

1 个答案:

答案 0 :(得分:0)

import requests
headers={"Content-Type": "multipart/form-data; charset=utf-8","Accept":"application/json"}
params={"img": open("image.jpg", mode="r"),"content_type": "0","max_th_size": "420"}
response = requests.post("https://api.pixhost.to/images", headers=headers, data=params)