首页 > 解决方案 > 最近使用 Overpass API 的 ConnectionErrors

问题描述

最近,当我尝试访问 Overpass API 时,我一直在从 Python 请求中弹出 ConnectionErrors。查询如下:

overpass_urls = ["https://overpass.kumi.systems/api/interpreter", "https://lz4.overpass-api.de/api/interpreter",
                     "https://overpass.kumi.systems/api/interpreter"]
    for i, url in enumerate(overpass_urls):
        resp, data = query_request(overpass_urls[i], osm_tag, bounds)
        if resp.status_code == 200:
            break
        else:
            print(resp.status_code)

def query_request(overpass_url, osm_tag, bounds):
    query = """
              [out:json]
              [timeout:30]
              [bbox:{s_bound}, {w_bound}, {n_bound}, {e_bound}];
              (
                  node[{tag}];
                  way[{tag}];
                  rel[{tag}];
              ); 
              out center body;
              >;
              out center qt;
          """.format(tag=osm_tag,
                     s_bound=bounds[0], w_bound=bounds[1], n_bound=bounds[2], e_bound=bounds[3])
    resp = requests.get(overpass_url, params={'data': query}, verify=False)
    data = resp.json()
    return resp, data

('连接中止。', FileNotFoundError(2, '没有这样的文件或目录'))

这是不断吐出的错误,以及来自 Python Requests 模块的 ConnectionError。这只是在最近几周才开始发生,我想知道 Overpass API 是否发生了变化,但我在变更日志中找不到任何内容。

标签: python-requestsoverpass-api

解决方案


推荐阅读