如何使用请求模块使用Python将JSON文件的内容发布到RESTFUL API

如何使用请求模块使用Python将JSON文件的内容发布到RESTFUL API,第1张

如何使用请求模块使用Python将JSON文件的内容发布到RESTFUL API

这应该可以,但是它适用于非常大的文件。

import requestsurl = 'https://api.example.com/api/dir/v1/accounts/9999999/orders'headers = {'Authorization' : ‘(some auth pre)’, '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)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5673604.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存