Upload a file with python using httplib

对着背影说爱祢 提交于 2019-12-04 19:36:20
gilesc

Currently, you aren't using the headers you've declared earlier in the code. You should provide them as the fourth argument to conn.request:

conn.request("POST", "/uploaddemo/files/", chunk, headers)

Also, side note: you can pass open("h1.jpg", "rb") directly into conn.request without reading it fully into chunk first. conn.request accepts file-like objects and it will be more efficient to stream the file a little at a time:

conn.request("POST", "/uploaddemo/files/", open("h1.jpg", "rb"), headers)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!