我试图重现与Python请求这个curl命令:Python的请求不会上传文件
curl -X POST -H 'Content-Type: application/gpx+xml' -H 'Accept: application/json' --data-binary @test.gpx "http://test.roadmatching.com/rest/mapmatch/?app_id=my_id&app_key=my_key" -o output.json
,卷曲请求工作正常。现在,我尝试使用Python:
import requests
file = {'test.gpx': open('test.gpx', 'rb')}
payload = {'app_id': 'my_id', 'app_key': 'my_key'}
headers = {'Content-Type':'application/gpx+xml', 'Accept':'application/json'}
r = requests.post("https://test.roadmatching.com/rest/mapmatch/", files=file, headers=headers, params=payload)
而我得到的错误:
<Response [400]>
{u'messages': [], u'error': u'Invalid GPX format'}
我在做什么错?我必须在某处指定data-binary
吗?
API被记录在这里:https://mapmatching.3scale.net/mmswag