How do I post a file over HTTP using the standard Python library

时间秒杀一切 提交于 2019-12-05 16:21:24

Standard python library has no support of multipart/form-data that required for post files through POST requests.

There is some recipes eg http://code.activestate.com/recipes/146306-http-client-to-post-using-multipartform-data/

u = urllib.urlopen(url, data=urllib.urlencode(
                             {'name': 'CI_VERSION', 
                              'value': str(version),
                              'file0': open(metadata_fpath).read(),
                               etc. 
                               etc.})) 

You can do this with urllib / urllib2. Above is a minimal example of sending a POST request.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!