我的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",
'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