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?

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.