Content-Type: multipart/form-data时python实现上传excel文件

代码为:

import requests

from requests_toolbeltimport MultipartEncoder

url1= "https://xxx/xx?auth_code=1d3a1c383deb427ebb5a0a877cc328ee&pid=189&__tData__=1618280514779"

data= MultipartEncoder({

    'action': 'preview',

    'auth_code': '1d3a1c383deb427ebb5a0a877cc328ee',

    'template': ('testfile.xlsx', open('/Users/mac/Downloads/testfile.xlsx', 'rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),

})

headers= {

    "Content-Type": data.content_type

}

r= requests.post(url1, data=data, headers=headers)

key= r.json()['key']

print(r.text)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容