【发布时间】:2019-10-26 07:39:44
【问题描述】:
我正在尝试访问我的地理编码服务器的 REST API:
[https://locator.stanford.edu/arcgis/rest/services/geocode/USA_StreetAddress/GeocodeServer](ArcGIS 服务器 10.6.1)
...使用 POST 方法(顺便说一句,可以使用一两个示例,似乎只有这个非常简短的“注意”关于何时使用 POST,而不是如何使用:https://developers.arcgis.com/rest/geocode/api-reference/geocoding-geocode-addresses.htm#ESRI_SECTION1_351DE4FD98FE44958C8194EC5A7BEF7D)。
我正在尝试使用 requests.post(),并且我想我已经设法让令牌被接受,等等...,但我不断收到 400 错误。
根据以前的经验,这意味着数据格式的某些内容不好,但我已经直接从 Esri 支持站点剪切并粘贴了这个测试对。
# import the requests library
import requests
# Multiple address records
addresses={
"records": [
{
"attributes": {
"OBJECTID": 1,
"Street": "380 New York St.",
"City": "Redlands",
"Region": "CA",
"ZIP": "92373"
}
},
{
"attributes": {
"OBJECTID": 2,
"Street": "1 World Way",
"City": "Los Angeles",
"Region": "CA",
"ZIP": "90045"
}
}
]
}
# Parameters
# Geocoder endpoint
URL = 'https://locator.stanford.edu/arcgis/rest/services/geocode/USA_StreetAddress/GeocodeServer/geocodeAddresses?'
# token from locator.stanford.edu/arcgis/tokens
mytoken = <GeneratedToken>
# output spatial reference id
outsrid = 4326
# output format
format = 'pjson'
# params data to be sent to api
params ={'outSR':outsrid,'f':format,'token':mytoken}
# Use POST to batch geocode
r = requests.post(url=URL, data=addresses, params=params)
print(r.json())
print(r.text)
这是我一直得到的:
{'error': {'code': 400, 'message': 'Unable to complete operation.', 'details': []}}
【问题讨论】:
-
如果有人想尝试使用没有密码保护的服务:sampleserver6.arcgisonline.com/arcgis/rest/services/Locators/…
标签: python rest post geocoding arcgis-server