taylorpaisie / random_python_scripts

Some python scripts for various different utility functions
0 stars 0 forks source link

When I run the code `python convert_to_lat_long.py`, it has error #1

Open liamxg opened 1 month ago

liamxg commented 1 month ago

Dear @taylorpaisie,

When I run the code python convert_to_lat_long.py, it has error:

python convert_to_lat_long.py
Do you want to enter a location manually (m) or use a file (f)? m
Enter a location: Beijing
Traceback (most recent call last):
  File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connection.py", line 196, in _new_conn
sock = connection.create_connection(
  File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/util/connection.py", line 85, in create_connection
  raise err
  File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/util/connection.py", line 73, in create_connection
  sock.connect(sa)
  socket.timeout: timed out

  The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 789, in urlopen
  response = self._make_request(
    File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 490, in _make_request
    raise new_e
    File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 466, in _make_request
    self._validate_conn(conn)
    File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1095, in _validate_conn
    conn.connect()
    File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connection.py", line 615, in connect
    self.sock = sock = self._new_conn()
    File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connection.py", line 205, in _new_conn
    raise ConnectTimeoutError(
      urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x10c793dc0>, 'Connection to nominatim.openstreetmap.org timed out. (connect timeout=1)')

      The above exception was the direct cause of the following exception:

        Traceback (most recent call last):
        File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/requests/adapters.py", line 667, in send
      resp = conn.urlopen(
        File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 873, in urlopen
        return self.urlopen(
          File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 873, in urlopen
          return self.urlopen(
            File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 843, in urlopen
            retries = retries.increment(
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/urllib3/util/retry.py", line 519, in increment
              raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
              urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=Beijing&format=json&limit=1 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x10c793dc0>, 'Connection to nominatim.openstreetmap.org timed out. (connect timeout=1)'))

              During handling of the above exception, another exception occurred:

                Traceback (most recent call last):
                File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/geopy/adapters.py", line 448, in _request
              resp = self.session.get(url, timeout=timeout, headers=headers)
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/requests/sessions.py", line 602, in get
              return self.request("GET", url, **kwargs)
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/requests/sessions.py", line 589, in request
              resp = self.send(prep, **send_kwargs)
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/requests/sessions.py", line 703, in send
              r = adapter.send(request, **kwargs)
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/requests/adapters.py", line 688, in send
              raise ConnectTimeout(e, request=request)
              requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=Beijing&format=json&limit=1 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x10c793dc0>, 'Connection to nominatim.openstreetmap.org timed out. (connect timeout=1)'))

              During handling of the above exception, another exception occurred:

                Traceback (most recent call last):
                File "/Volumes/WD_BLACK/0_BEAST/taylorpaisie/random_python_scripts/convert_to_lat_long.py", line 61, in <module>
                coordinates = get_lat_lon(location)
              File "/Volumes/WD_BLACK/0_BEAST/taylorpaisie/random_python_scripts/convert_to_lat_long.py", line 15, in get_lat_lon
              location_data = geolocator.geocode(location)
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/geopy/geocoders/nominatim.py", line 297, in geocode
              return self._call_geocoder(url, callback, timeout=timeout)
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/geopy/geocoders/base.py", line 368, in _call_geocoder
              result = self.adapter.get_json(url, timeout=timeout, headers=req_headers)
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/geopy/adapters.py", line 438, in get_json
              resp = self._request(url, timeout=timeout, headers=headers)
              File "/Users/liam/opt/miniconda3/lib/python3.9/site-packages/geopy/adapters.py", line 460, in _request
              raise GeocoderUnavailable(message)
              geopy.exc.GeocoderUnavailable: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=Beijing&format=json&limit=1 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x10c793dc0>, 'Connection to nominatim.openstreetmap.org timed out. (connect timeout=1)'))

Best, Liam

taylorpaisie commented 1 month ago

It looks like this is a network issue with geopy, i can try to look into it more but sometimes this can just happen with the python package.

liamxg commented 1 month ago

Thanks to know this, need I change the python version?