反向地址解析-由于目标计算机主动拒绝连接,因此无法建立连接'

问题描述 投票:0回答:1

我有一个Freemium帐户,并生成了2个REST API密钥。使用任一键时,出现以下错误-

HTTPConnectionPool(host ='batch.geocoder.ls.hereapi.com',port = 80):URL重试次数超过了最大重试次数:/6.2/jobs? prox =%5B24.47%2C + 24.78%2C + 48.2%2C + -33.87%2C + 50.85%2C + 26.21%2C + -22.92%2C + -22.34%2C + 50.91%2C + 47.41%2C + -33.39%2C + 39.92 %2C + 39.79%5D%2C%5B54.34%2C + 55.6%2C + 16.36%2C + 151.21%2C + 4.36%2C + 50.57%2C + -43.24%2C + -49.05%2C + -114.07%2C + 8.54%2C + -70.52%2C + 116.17%2C + 116.51%5D&mode = retrieveAddresses&maxresults = 1&gen = 9&apiKey = -17nmoOoBBAH3fHWUg2QYL6FB3qLcEvb88MRFTUuE5A(由NewConnectionError引起(':拒绝目标成功建立新连接的计算机:[无法成功建立100个连接:它))

我正在关注[https://developer.here.com/blog/reverse-geocoding-a-location-using-python]我还遵循文档来构建我的GET请求[https://developer.here.com/documentation/examples/rest/geocoder/reverse-geocode],我不知道发生了什么。过去一周我一直在努力解决这个问题。它超越了我。我是编程,python,stackoverflow的新手。技术支持,请您指教?谢谢。

我正在使用Python。目标是从CSV文件中反向对25,000个点进行地理编码,然后写入CSV文件。我的反向地理编码代码-

# Request URL
request_url = "https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json"

# API key
#api_key1 = 'MY API KEY 1'
api_key2 = 'MY API KEY 2'

# setting the parameters to be sent along with the request_url in the GET request
parametres = {
                'prox': '{},{}'.format(latitude_list,longitude_list),
                'mode': 'retrieveAddresses',
                'maxresults': 1,
                'gen': 9,
                'apiKey': api_key2                 
             }

# send a GET request
response = requests.get (url = request_url, params = parametres)
print(response.status_code)

# check if the request was successful and get the JSON response data
if response.status_code == 200:
    print('Request successful.')
    data = response.json()
    print(data)
else:
    print('Request failed.')
here-api
1个回答
0
投票

嗨,请在这里检查正确的工作代码-

import random
import time
import pandas as pd
import requests


latitude = 12.9716
longitude = 77.5946
file_name = 'data.csv'


def generate_random_data(lat, lon, num_rows, file_name):
    with open(file_name, 'a') as output:
        output.write('timestamp,latitude,longitude\n')
        for _ in range(num_rows):
            time_stamp = time.time()
            generated_lat = random.random()/100
            generated_lon = random.random()/100
            output.write("{},{},{}\n".format(
                time_stamp, lat+generated_lat, lon+generated_lon))


generate_random_data(latitude, longitude, 10, file_name)

# To read 6th row data
data = pd.read_csv("data.csv", skiprows=5, nrows=1)

# To print the values
print(data)

# To convert values into list
list_value = data.values.tolist()

# Latitude and Longitude
latitude = list_value[0][1]
longitude = list_value[0][2]

print(latitude, longitude)

request_url = "https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json"

# API key

api_key = 'your rest api key'

# setting the parameters to be sent along with the request_url in the GET request
parametres = {
    'prox': '{},{}'.format(latitude, longitude),
    'mode': 'retrieveAddresses',
    'maxresults': 1,
    'gen': 9,
    'apiKey': api_key
}

# send a GET request
response = requests.get(url=request_url, params=parametres)
print(response.status_code)

# check if the request was successful and get the JSON response data
if response.status_code == 200:
    print('Request successful.')
    data = response.json()
    print(data)
else:
    print('Request failed.')

它给出以下响应-

请求成功。 {'Response':{'MetaInfo':{'Timestamp':'2020-06-17T11:50:24.706 + 0000'},'View':[{'_type': 'SearchResultsViewType','ViewId':0,'Result':[{'Relevance':1.0, '距离':-429.0,'方向':16.2,'匹配级别':'区域', 'MatchQuality':{'Country':1.0,'State':1.0,'County':1.0,'City': 1.0,'District':1.0,'PostalCode':1.0},'Location':{'LocationId':'NT_ncA49aCPF2GKSWJE4kP26C','LocationType':'area', 'DisplayPosition':{'Latitude':12.98721,'Longitude':77.60402}, 'MapView':{'TopLeft':{'Latitude':12.99579,'Longitude':77.58896}, 'BottomRight':{'Latitude':12.97306,'Longitude':77.61544}}, '地址':{'Label':'Shivajinagar,Bengaluru,KA,印度','国家/地区: 'IND','State':'KA','County':'Bengaluru','City':'Bengaluru', '区':'Shivajinagar','邮政编码':'560051','附加数据': [{'value':'India','key':'CountryName'},{'value':'Karnataka', 'key':'StateName'},{'value':'Bengaluru','key':'CountyName'}]}, 'MapReference':{'ReferenceId':'846137287','MapId':'RRAM20115', 'MapVersion':'Q1 / 2020','MapReleaseDate':'2020-06-08', 'SideOfStreet':'noth','CountryId':'22806254','StateId': '22798588','CountyId':'22799633','CityId':'22803543', 'DistrictId':'28032363'}}}}}}}}]

希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.