这应该可以,但是它适用于非常大的文件。
import requests
url = 'https://api.example.com/api/dir/v1/accounts/9999999/orders'
headers = {'Authorization' : ‘(some auth code)’, 'Accept' : 'application/json', 'Content-Type' : 'application/json'}
r = requests.post(url, data=open('example.json', 'rb'), headers=headers)
如果要发送较小的文件,请以字符串形式发送。
contents = open('example.json', 'rb').read()
r = requests.post(url, data=contents, headers=headers)