2

I have this curl call to a local graphhopper server which works:

curl -XPOST -H "Content-Type: application/gpx+xml" -d @home/jd/test1.gpx "localhost:8989/match?vehicle=car&type=json"

I now want to automate this call in python and got the following so far:

import requests

url = 'http://localhost:8989/match'

headers = {'Content-Type': "application/gpx+xml"}
files = {'upload_file': open('home/jd/test1.gpx','rb')}
values = {'vehicle': 'car', 'type': 'json'}

r = requests.post(url, files=files, data=values, headers=headers)

print (r.status_code)
print (r.raise_for_status())

I get a Bad Request for URL http://localhost:8989/match

what am I missing here?

T.Klemmer
  • 41
  • 2

1 Answers1

2

Ok I found the solution:

Since the Post request for Curl uploads a file I have to pass the file objekt direktly into data. I did put the other parameters back into the URL.

import requests

url = 'http://localhost:8989/match?vehicle=car&type=json'

headers = {'Content-Type': 'application/gpx+xml'}

r = requests.post(url, data=open('/home/jd/test1.gpx','rb'), headers= headers)

print (r.status_code)
print (r.raise_for_status())
print (r.text)

works like a charm!

T.Klemmer
  • 41
  • 2