wavded / ogre

ogr2ogr geojson-focused web client
http://ogre.adc4gis.com
MIT License
266 stars 79 forks source link

HTTP Post Unexpected Field #98

Closed scmj closed 2 years ago

scmj commented 2 years ago

Hi there,

I have recently encountered the error message "MulterError: Unexpected field" when running the script below. It ran with no issues under 2.1.0. The error arises when specifying a targetSrs (otherwise conversion gives back no issues), and I´m assuming it has something to do with the structure of the POST request. I would really appreciate someone would shed some light over the obvious mistake i´m making but that i´m not really seeing. Thanks in advance!


url= https://localhost:3000/convert

gmlfile = ('test.gml')

payload = {"upload":('test.gml' , open(gmlfile, "rb")), "targetSrs":"EPSG:4326"}

response = requests.post(url, files=payload)

file_name = 'result.json'

with open(file_name,'w') as f:
  f.write(response.text)
  f.close()
wavded commented 2 years ago

This looks like the python requests library. According the documentation, it seems like passing targetSrs as a file with text may be the issue. Should that use the data parameter for that part? Multer expects only one file named upload and guards against other files being sent. It seems like the multipart request may be labelling targetSrs as a file here.

Caveat, I know very little about python requests library and may be totally wrong here! If that doesn't work, are you able to send the raw request to me? Note this isn't an issue using the web UI and the way the browser is formatting a multipart request.

scmj commented 2 years ago

You were absolutely right, it was a python requests library issue. I separated the request in two as shown below, and it worked. I was so fixated on Multer that I overlooked the obvious mistake I made. Thank you very much!

url= https://localhost:3000/convert

gmlfile = ('test.gml')

payload = {"upload":('test.gml' , open(gmlfile, "rb"))}

values = {"targetSrs":"EPSG:4326"}

response = requests.post(url, files=payload, data=values)

file_name = 'result.json'

with open(file_name,'w') as f:
  f.write(response.text)
  f.close()