python 使用 requests,requests_toolbelt上传图片文件,报错:AttributeError: 'int' object has no attribute 'encode'

问题

在使用 python requests_toolbelt 库上传excel 文件的过程中,几类问题报错

1 MultipartEncoder 支持中文文件名称上传

开始遇到的报错以为是中文文件名称不支持,查到的解决方案是修改 requests 依赖的 urllib3 的源码问题,解决方案是修改源码文件
https://blog.csdn.net/u013250071/article/details/82493892

经过自测,发现支持中文显示
image

2 报错:AttributeError: 'int' object has no attribute 'encode'

经过查询资料,发现是 MultipartEncoder 类中的字段 value不能是 int 类型,需要转成str才可以
查询资料如下:
https://www.likecs.com/show-203533247.html#sc=1938
image

经过自己验证,发送请求成功:
image

posted @ 2022-11-23 16:14  黑色毛头鹰  阅读(501)  评论(0)    收藏  举报