加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – requests:发布multipart / form-data

发布时间:2020-12-20 11:52:40 所属栏目:Python 来源:网络整理
导读:我的API: class FileView(APIView): parser_classes = (MultiPartParser,) def post(self,request): do something with request.FILES.dict().iteritems() 我的requests文件: try: headers = { 'content-type': "multipart/form-data",'authorization': "B
我的API:

class FileView(APIView):
    parser_classes = (MultiPartParser,)
    def post(self,request):
        do something with request.FILES.dict().iteritems()

我的requests文件:

try:
    headers = {
        'content-type': "multipart/form-data",'authorization': "Basic ZXNlbnRpcmVcYdddddddddddddd",'cache-control': "no-cache",}
    myfile = {"file": ("filexxx",open(filepath,"rb"))}

    response = requests.request("POST",verify=False,url=url,data=myfile,headers=headers)

    print(response.text)
except Exception as e:
    print "Exception:",e

错误:

“多部分表单解析错误 – 多部分中的无效边界:无”

发布文件的正确方法是什么?谢谢

requests.version
‘2.10.0’

解决方法

从标题中删除了’content-type’,现在它可以正常工作了

try:
    headers = {
        'authorization': "Basic ZXNlbnRpcmVcYdddddddddddddd",e

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读