【发布时间】:2020-06-16 07:57:18
【问题描述】:
我从https://www.n2yo.com/api/ 流式传输 RESTful API 数据,用于跟踪卫星位置。 我使用带有 Elasticsearch 的 python 客户端。我每 10 秒将流式数据保存到 ES,并由 Kibana 进行可视化。我的 ES 版本是 6.4.3
我的代码是:
URL = "https://www.n2yo.com/rest/v1/satellite/positions/25544/41.702/-76.014/0/2/&apiKey= your key"
es = Elasticsearch('http://ip:port',timeout=600)
settings = { "settings": {
"number_of_shards":1,
'number_of_replicas':0
},
"mappings" : {
"document" : {
"properties":{
"geo": {
"type": "geo_point"
}
}
}
}
}
try:
es.indices.create(index = "spacestation", body=settings)
except RequestError as es1:
print('Index already exists!!')
sys.exit(1)
def collect_data():
data = requests.get(url = URL).json()
del data['positions'][1]
new_data = {'geo':{'lat':data['positions'][0]['satlatitude'],
'lon':data['positions'][0]['satlongitude']},
'satname': data['info']['satname'], 'satid': data['info']['satid'],
'timestamp':datetime.fromtimestamp(data['positions'][0]['timestamp']).isoformat()
}
es.index(index='spacestation', doc_type='document', body=new_data)
schedule.every(10).seconds.do(collect_data)
while True:
schedule.run_pending()
time.sleep(1)
我的问题是:昨天我失去了连接。错误如下,
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.n2yo.com', port=443): 最大重试次数超出 url: /rest/v1/satellite/positions/25544/41.702/-76.014/0/ 2/&apiKey= (由NewConnectionError(': 无法建立新连接: [Errno -3] 名称解析临时失败',))
当我重新运行我的代码时,我不能,因为索引已经存在。如果我删除索引,我将丢失已经在 ES 中的数据。我可以做什么?我需要保留我保存的数据,并且我需要从现在开始运行该作业。请问有什么解决办法吗?
【问题讨论】:
标签: python python-3.x elasticsearch restful-url