python请求将字符串作为文件发送

python请求将字符串作为文件发送,第1张

python请求字符串作为文件发送

在POST的多部分编码文件部分下,仔细阅读“请求快速入门”页面。

在这里,您会发现:

如果需要,可以发送字符串作为文件接收:

>>> url = 'http://httpbin.org/post'>>> files = {'file': ('report.csv', 'some,data,to,sendnanother,row,to,sendn')}>>> r = requests.post(url, files=files)>>> r.text{  ...  "files": {    "file": "some,data,to,send\nanother,row,to,send\n"  },  ...}

请注意,这

"file"
是服务器期望的文件上载字段的名称。它对应于以下HTML:

<input type="file" name="file">


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存