-3

Мy query produces the following error

{"ExportedDataFile":["The ExportedDataFile field is required."]}

import requests

files = {'file': open('33332815-2019-04-191419.xml', 'rb')}
payload = {'ExportedDataFile': files, 'Token': 'test'}
r = requests.post("http://????", data=payload)
print(r.text)
Iguananaut
  • 21,810
  • 5
  • 50
  • 63
mchovo
  • 11
  • 5
  • Why are you passing in the `files` dictionary as the `ExportedDataFile` key in the `data` mapping? You need to pass in that dictionary as the `files` argument, possibly with the key in that dictionary set to `ExportedDataFile`, so `files = {'ExportedDataFile': open(...)}`, and `payload = {'Token': 'test'}`, then `requests.post(url, data=payload, files=files)`. See the duplicate. – Martijn Pieters Apr 19 '19 at 13:00
  • You passed an open file object in `{'file': ...}`. Files should be passed via `files` argument to `requests.post` presuming that the server on the other end is expecting some multipart MIME document: http://docs.python-requests.org/en/master/api/#requests.request – Iguananaut Apr 19 '19 at 13:00

1 Answers1

-1

As @Martijn Pieters points out, you can post files, like so:

import requests

files = {'ExportedDataFile': open('33332815-2019-04-191419.xml', 'rb')}
payload = {'Token': 'test'}
r = requests.post("http://????", files=files, data=payload)
print(r.text)
cs95
  • 379,657
  • 97
  • 704
  • 746
brunns
  • 2,689
  • 1
  • 13
  • 24