Python 3.x 如何在路由匹配API上使用python获取POST请求?

Python 3.x 如何在路由匹配API上使用python获取POST请求?,python-3.x,python-requests,here-api,Python 3.x,Python Requests,Here Api,我尝试使用python的请求库执行POST请求,如下所示: url=”https://rme.api.here.com/2/matchroute.json?routemode=car&filetype=CSV&app_id={id}&app_code={code}” response=requests.post(url,data='Datasets/rtHereTest.csv') 我得到的答复是400码 {'faultCode': '16a6f70f-1fa3-4b57-9ef3-a0a440

我尝试使用python的请求库执行POST请求,如下所示:

url=”https://rme.api.here.com/2/matchroute.json?routemode=car&filetype=CSV&app_id={id}&app_code={code}”
response=requests.post(url,data='Datasets/rtHereTest.csv')

我得到的答复是400码

{'faultCode': '16a6f70f-1fa3-4b57-9ef3-a0a440f8a42e',
 'responseCode': '400 Bad Request',
 'message': 'Column LATITUDE missing'}
但是,在我的数据集中,我拥有HERE API文档中所需的所有标题,以便能够进行调用


如果我做错了什么,我不太理解POST调用或需求,因为这里的文档没有明确给出很多示例

post请求的数据字段应该包含实际数据,而不仅仅是文件名。请先尝试加载文件:

f = open('Datasets/rtHereTest.csv', 'r')
url = "https://rme.api.here.com/2/matchroute.json?routemode=car&filetype=CSV&app_id={id}&app_code={code}"
response = requests.post(url, data=f.read())
f.close()
以下是我在自己的代码中使用的内容,以及之前定义的坐标:

query = 'https://rme.api.here.com/2/matchroute.json?routemode=car&app_id={id}&app_code={code}'.format(id=app_id, code=app_code)
coord_strings = ['{:.5f},{:.5f}'.format(coord[0], coord[1]) for coord in coords]
data = 'latitude,longitude\n' + '\n'.join(coord_strings)
result = requests.post(query, data=data)

您可以尝试使用以下格式发布数据

import requests
    url = "https://rme.api.here.com/2/matchroute.json"
    querystring = {"routemode":"car","app_id":"{app_id}","app_code":"{app_code}","filetype":"CSV"}
    data=open('path of CSV file','r')
    headers = {'Content-Type': "Content-Type: text/csv;charset=utf-8",
        'Accept-Encoding': "gzip, deflate",
        }
    response = requests.request("POST", url, data=data.read().encode('utf-8'), params=querystring,headers=headers)
    print(response.status_code)

希望这有帮助

谢谢你的帮助!我现在明白了,太棒了!我一定会尝试一下,现在肯定更有意义了。