python+requests——post提交文件

url = 'http://httpbin.org/post'

files = {'file': open('report.xls', 'rb')}

r = requests.post(url, files=files)


#你可以显式地设置文件名,文件类型和请求头:
url = 'http://httpbin.org/post'

files = {'file': ('report.xls', open('report.xls', 'rb'), 'application/vnd.ms-excel', {'Expires': '0'})}


r = requests.post(url, files=files)

猜你喜欢

转载自www.cnblogs.com/xiaobaibailongma/p/12346209.html