I have this at django
@csrf_exempt
@require_http_methods(['POST'])
@api_token
def foo(request):
upload_file = request.FILES['file']
random_function(upload_file)
return HttpResponse('done')
and this at another python file
import requests
url = "http://127.0.0.1:8000/api/external/path"
payload = {}
files = {'file': open('csv_file.csv', 'rb')}
headers = {
'x-api-key': 'api-key-token',
'Content-Type': 'application/form-data'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text.encode('utf8'))
the problem is that when I executed the python file I got this error
django.utils.datastructures.MultiValueDictKeyError: 'file'
it was like request.FILES
can't find file
name
but when I execute it from postman it works fine