我向Google的地理编码API请求了40,000次,几乎所有请求都成功了,但是只有少数请求不起作用。(回复为ZERO_RESULT)
我认为这将是一个编码问题,但是当我在chrome中插入解析的url时,它会响应结果。但是,当我尝试使用网址完全相同的python请求进行尝试时,它会回复ZERO_RESULTS(这实际上没有任何结果)
这就是我得到的
get_geodata_debug("650 FROM ROAD SOUTH LOBBY, 4TH FLOOR PARAMUS NJ 07652")
我删除了我的api密钥。
raw address = 650 FROM ROAD SOUTH LOBBY, 4TH FLOOR PARAMUS NJ 07652
parsed address = 650+FROM+ROAD+SOUTH+LOBBY%2C+4TH+FLOOR+PARAMUS+NJ+07652
url = https://maps.googleapis.com/maps/api/geocode/json?key=MYAPIKEY&address=650+FROM+ROAD+SOUTH+LOBBY%2C+4TH+FLOOR+PARAMUS+NJ+07652
{
"results" : [],
"status" : "ZERO_RESULTS"
}
def get_geodata_debug(address):
_results_status = ""
_results_length = 0
_location ={}
print("raw address = "+address)
address = parse.quote_plus(str(address))
print("parsed address = "+address)
params = "key=%s&address=%s"%(key,address)
url = 'https://maps.googleapis.com/maps/api/geocode/json?%s'%(params)
print("url = "+url)
response = requests.get(url)
print(response.text)
if response.status_code == 200:
response_json = response.json()
_results_status = response_json["status"]
if _results_status == 'OK':
_results_length = len(response_json["results"])
_location = response_json["results"][0]["geometry"]["location"]
return response.status_code, _results_status, _results_length, _location
我想要在python和chrome中获得相同的结果