Python POST 请求 returns 只是结果的一部分
Python POST request returns just part of the result
我正在使用 HERE 地图 API:
https://developer.here.com/documentation/examples/rest/geocoder/multi-reverse-geocode-landmarks
当我这样使用 curl 请求时:
curl \
-X POST \
-H 'Content-Type: *' \
-H 'Cache-Control: no-cache' \
-d 'id=0001&prox=52.5309,13.3845,500
id=002&prox=52.5509,13.3945,500' \
'https://reverse.geocoder.api.here.com/6.2/multi-reversegeocode.json?mode=retrieveLandmarks&gen=9&maxresults=1&app_id=APP_ID&app_code=APP_CODE'*
我得到了正确的回复:
{"Response":{"MetaInfo":{"Timestamp":"2020-02-11T20:52:22.096+0000"},"Item":[{"ItemId":1,"Result":[{"Relevance":1.0,"Distance":161.2,"MatchLevel":"landmark","MatchQuality":{ "Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0], "HouseNumber":1.0,"PostalCode":1.0,"Name":1.0},"Location":{"LocationId":"NT_2tJfMbwzYPMKlNdDmb5jBB_p_bUfMBOrFIallcDBNjbQ6VD","LocationType": "cemetery","Name":"Dorotheenstädtischer Friedhof","DisplayPosition":{"Latitude":52.52877,"Longitude":13.38299},"NavigationPosition":[{ "Latitude":52.52882,"Longitude":13.38524}],"MapView":{"TopLeft":{"Latitude":52.5298942,"Longitude":13.3811422},"BottomRight":{"Latitude":52.5276458,"Longitude":13.3848378}},"Address":{"Label":"Chausseestraße 126, 10115 Berlin, Deutschland","Country":"DEU","State":"Berlin","County":"Berlin","City":"Berlin","District":"Mitte","Street":"Chausseestraße","HouseNumber":"126","PostalCode":"10115","AdditionalData":[{"value":"Deutschland","key":"CountryName"},{"value":"Berlin","key":"StateName"},{"value" :"Berlin","key":"CountyName"}]},"MapReference":{"MapId":"UWAM19149","MapVersion":"Q1/2019","MapReleaseDate":"2020-01-24","CountryId":"20147700","StateId":"20187401","CountyId":"20187402","CityId":"20187403","DistrictId":"20187417","PlaceId":"898512796"}}}]},{"ItemId":2,"Result":[{"Relevance":1.0,"Distance":-36.1,"MatchLevel":"landmark","MatchQuality":{"Country":1.0,"State":1.0 ,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"HouseNumber":1.0,"PostalCode":1.0,"Name":1.0},"Location":{"LocationId":"NT_kVPSoMMfo8QWTG-W48-JrD_p_CHPEQ-9guKqwHPBzIZyhkB","LocationType":"park","Name":"Sportplatz Wedding","DisplayPosition":{"Latitude":52.5512,"Longitude":13.394},"NavigationPosition":[{"Latitude":52.55056,"Longitude":13.39432}],"MapView":{"TopLeft":{"Latitude":52.5523242,"Longitude":13.3921512},"BottomRight":{"Latitude":52.5500758,"Longitude":13.3958488}},"Address":{"Label":"Behmstraße 29, 13357 Berlin, Deutschland","Country":"DEU","State":"Berlin","County":"Berlin","City": "Berlin","District":"Gesundbrunnen","Street":"Behmstraße","HouseNumber":"29","PostalCode":"13357", "AdditionalData":[{"value":"Deutschland","key":"CountryName"},{"value":"Berlin","key":"StateName"},{"value":"Berlin","key":"CountyName"}]},"MapReference":{"MapId": "UWAM19149","MapVersion":"Q1/2019","MapReleaseDate":"2020-01-24","CountryId":"20147700","StateId":"20187401 ","CountyId":"20187402","CityId":"20187403","DistrictId":"20428239","PlaceId":"1109857527"}}}]}]}}
但是当我从 python 请求库中执行相同操作时,我只从响应中获得最后一项:
import requests
import json
URL = "https://reverse.geocoder.api.here.com/6.2/multi-reversegeocode.json
headers = {'content-type': '*', "Cache-Control": "no-cache"}
data = [('id', '0001'), ('prox', '52.5309,13.3845,500'),
('id', '0002'), ('prox', '52.5509,13.3945,500')]
params = {
"app_id": <APP_ID>,
"app_code": <APP_CODE>,
"mode": "retrieveLandmarks",
"maxresults": 1,
"gen": 9,
}
res = requests.post(URL, params=params, data=data, headers=headers)
print(res.json())
{'Response': {'MetaInfo': {'Timestamp': '2020-02-11T20:53:58.558+0000'}, 'Item': [{'ItemId': 2, 'Result': [{'Relevance': 1.0, 'Distance': -36.1, 'MatchLevel': 'landmark', 'MatchQuality': {'Country': 1.0, 'State': 1.0, 'County': 1.0, 'City': 1.0, 'District': 1.0, 'Street': [1.0] , 'HouseNumber': 1.0, 'PostalCode': 1.0, 'Name': 1.0}, 'Location': {'LocationId': 'NT_kVPSoMMfo8QWTG-W48-JrD_p_CHPEQ-9guKqwHPBzIZyhkB', 'LocationType' : 'park', 'Name': 'Sportplatz Wedding', 'DisplayPosition': {'Latitude': 52.55056, 'Longitude': 13.39432}, 'MapView': { 'TopLeft':{'Latitude':52.5516842,'Longitude':13.3924713},'BottomRight':{'Latitude':52.5494358,'Longitude':13.3961687}},'Address': {'Label': 'Behmstraße 29, 13357 Berlin, Deutschland', 'Country': 'DEU', 'State': 'Berlin', 'County': 'Berlin', 'City': 'Berlin', 'District': 'Gesundbrunnen', 'Street': 'Behmstraße', 'HouseNumber': '29', 'PostalCode': '13357', 'AdditionalData': [{'value': 'Deutschland', 'key': 'CountryName'}, {'value': 'Berlin', 'key': 'StateName'}, {'value': 'Berlin', 'key': 'CountyName'}]}, 'MapReference': {'CountryId': '20147700', 'StateId': '20187401', 'CountyId': '20187402', 'CityId': '20187403', 'DistrictId': '20428239', 'PlaceId': '1109857527'}}}]}]}}
我怎样才能得到完整的结果?
尝试将 data
作为字符串传递。 data
中的第二行似乎被忽略了。 curl 的 -d 选项根本不会改变或编码数据,只会准确发送您告诉它的内容。
import requests
url = "https://reverse.geocoder.api.here.com/6.2/multi-reversegeocode.json?mode=retrieveLandmarks&gen=9&maxresults=1&app_id=<APP_ID>&app_code=<APP_CODE>"
payload = "id=0001&prox=52.5309,13.3845,500\nid=002&prox=52.5509,13.3945,500\n"
headers = {
'Content-Type': '*'
}
response = requests.request("POST", url, headers=headers, data = payload)
我正在使用 HERE 地图 API: https://developer.here.com/documentation/examples/rest/geocoder/multi-reverse-geocode-landmarks
当我这样使用 curl 请求时:
curl \
-X POST \
-H 'Content-Type: *' \
-H 'Cache-Control: no-cache' \
-d 'id=0001&prox=52.5309,13.3845,500
id=002&prox=52.5509,13.3945,500' \
'https://reverse.geocoder.api.here.com/6.2/multi-reversegeocode.json?mode=retrieveLandmarks&gen=9&maxresults=1&app_id=APP_ID&app_code=APP_CODE'*
我得到了正确的回复:
{"Response":{"MetaInfo":{"Timestamp":"2020-02-11T20:52:22.096+0000"},"Item":[{"ItemId":1,"Result":[{"Relevance":1.0,"Distance":161.2,"MatchLevel":"landmark","MatchQuality":{ "Country":1.0,"State":1.0,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0], "HouseNumber":1.0,"PostalCode":1.0,"Name":1.0},"Location":{"LocationId":"NT_2tJfMbwzYPMKlNdDmb5jBB_p_bUfMBOrFIallcDBNjbQ6VD","LocationType": "cemetery","Name":"Dorotheenstädtischer Friedhof","DisplayPosition":{"Latitude":52.52877,"Longitude":13.38299},"NavigationPosition":[{ "Latitude":52.52882,"Longitude":13.38524}],"MapView":{"TopLeft":{"Latitude":52.5298942,"Longitude":13.3811422},"BottomRight":{"Latitude":52.5276458,"Longitude":13.3848378}},"Address":{"Label":"Chausseestraße 126, 10115 Berlin, Deutschland","Country":"DEU","State":"Berlin","County":"Berlin","City":"Berlin","District":"Mitte","Street":"Chausseestraße","HouseNumber":"126","PostalCode":"10115","AdditionalData":[{"value":"Deutschland","key":"CountryName"},{"value":"Berlin","key":"StateName"},{"value" :"Berlin","key":"CountyName"}]},"MapReference":{"MapId":"UWAM19149","MapVersion":"Q1/2019","MapReleaseDate":"2020-01-24","CountryId":"20147700","StateId":"20187401","CountyId":"20187402","CityId":"20187403","DistrictId":"20187417","PlaceId":"898512796"}}}]},{"ItemId":2,"Result":[{"Relevance":1.0,"Distance":-36.1,"MatchLevel":"landmark","MatchQuality":{"Country":1.0,"State":1.0 ,"County":1.0,"City":1.0,"District":1.0,"Street":[1.0],"HouseNumber":1.0,"PostalCode":1.0,"Name":1.0},"Location":{"LocationId":"NT_kVPSoMMfo8QWTG-W48-JrD_p_CHPEQ-9guKqwHPBzIZyhkB","LocationType":"park","Name":"Sportplatz Wedding","DisplayPosition":{"Latitude":52.5512,"Longitude":13.394},"NavigationPosition":[{"Latitude":52.55056,"Longitude":13.39432}],"MapView":{"TopLeft":{"Latitude":52.5523242,"Longitude":13.3921512},"BottomRight":{"Latitude":52.5500758,"Longitude":13.3958488}},"Address":{"Label":"Behmstraße 29, 13357 Berlin, Deutschland","Country":"DEU","State":"Berlin","County":"Berlin","City": "Berlin","District":"Gesundbrunnen","Street":"Behmstraße","HouseNumber":"29","PostalCode":"13357", "AdditionalData":[{"value":"Deutschland","key":"CountryName"},{"value":"Berlin","key":"StateName"},{"value":"Berlin","key":"CountyName"}]},"MapReference":{"MapId": "UWAM19149","MapVersion":"Q1/2019","MapReleaseDate":"2020-01-24","CountryId":"20147700","StateId":"20187401 ","CountyId":"20187402","CityId":"20187403","DistrictId":"20428239","PlaceId":"1109857527"}}}]}]}}
但是当我从 python 请求库中执行相同操作时,我只从响应中获得最后一项:
import requests
import json
URL = "https://reverse.geocoder.api.here.com/6.2/multi-reversegeocode.json
headers = {'content-type': '*', "Cache-Control": "no-cache"}
data = [('id', '0001'), ('prox', '52.5309,13.3845,500'),
('id', '0002'), ('prox', '52.5509,13.3945,500')]
params = {
"app_id": <APP_ID>,
"app_code": <APP_CODE>,
"mode": "retrieveLandmarks",
"maxresults": 1,
"gen": 9,
}
res = requests.post(URL, params=params, data=data, headers=headers)
print(res.json())
{'Response': {'MetaInfo': {'Timestamp': '2020-02-11T20:53:58.558+0000'}, 'Item': [{'ItemId': 2, 'Result': [{'Relevance': 1.0, 'Distance': -36.1, 'MatchLevel': 'landmark', 'MatchQuality': {'Country': 1.0, 'State': 1.0, 'County': 1.0, 'City': 1.0, 'District': 1.0, 'Street': [1.0] , 'HouseNumber': 1.0, 'PostalCode': 1.0, 'Name': 1.0}, 'Location': {'LocationId': 'NT_kVPSoMMfo8QWTG-W48-JrD_p_CHPEQ-9guKqwHPBzIZyhkB', 'LocationType' : 'park', 'Name': 'Sportplatz Wedding', 'DisplayPosition': {'Latitude': 52.55056, 'Longitude': 13.39432}, 'MapView': { 'TopLeft':{'Latitude':52.5516842,'Longitude':13.3924713},'BottomRight':{'Latitude':52.5494358,'Longitude':13.3961687}},'Address': {'Label': 'Behmstraße 29, 13357 Berlin, Deutschland', 'Country': 'DEU', 'State': 'Berlin', 'County': 'Berlin', 'City': 'Berlin', 'District': 'Gesundbrunnen', 'Street': 'Behmstraße', 'HouseNumber': '29', 'PostalCode': '13357', 'AdditionalData': [{'value': 'Deutschland', 'key': 'CountryName'}, {'value': 'Berlin', 'key': 'StateName'}, {'value': 'Berlin', 'key': 'CountyName'}]}, 'MapReference': {'CountryId': '20147700', 'StateId': '20187401', 'CountyId': '20187402', 'CityId': '20187403', 'DistrictId': '20428239', 'PlaceId': '1109857527'}}}]}]}}
我怎样才能得到完整的结果?
尝试将 data
作为字符串传递。 data
中的第二行似乎被忽略了。 curl 的 -d 选项根本不会改变或编码数据,只会准确发送您告诉它的内容。
import requests
url = "https://reverse.geocoder.api.here.com/6.2/multi-reversegeocode.json?mode=retrieveLandmarks&gen=9&maxresults=1&app_id=<APP_ID>&app_code=<APP_CODE>"
payload = "id=0001&prox=52.5309,13.3845,500\nid=002&prox=52.5509,13.3945,500\n"
headers = {
'Content-Type': '*'
}
response = requests.request("POST", url, headers=headers, data = payload)