要求:发布多部分/表单数据 [英] requests: post multipart/form-data
本文介绍了要求:发布多部分/表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的API:
class FileView(APIView):
parser_classes = (MultiPartParser,)
def post(self, request):
do something with request.FILES.dict().iteritems()
我的请求文件:
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
错误:
多部分表单解析错误-无效的多部分边界:无
什么是对的谢谢
请求。 strong>版本
'2.10.0'
requests.version '2.10.0'
推荐答案
从标题中删除内容类型,现在可以使用
Removed 'content-type' from the headers, now it works
try:
headers = {
'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
这篇关于要求:发布多部分/表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文