Geopy Not Working in Streamlit Cloud


Geopy not Working on Streamlit Cloud , but working on Local system

Steps to reproduce

Code snippet:

from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent = "geoapiExercises")

def countries(x):
    #This function will use the Geolocator API and find the Country of the user. 
    # We split the result and provided the last part which contains the country name.
        location = geolocator.geocode(x,language='en',timeout=None)
        return str(location.raw['display_name'].split(',')[-1]).strip()
    except :
        return None


If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

the function works for this input in local env , but does not work for any input in Streamlit Cloud env

Actual behavior:

This Should return ‘India’ but gives error
**geopy.exc.GeocoderInsufficientPrivileges: Non-successful status code 403**

Debug info

  • Streamlit version: streamlit-1.22.0
  • Python version: 3.9
  • Using streamlit Cloud
  • OS version: NA
  • Browser version: Latest

Requirements file



  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

From a StackOverflow thread about the error message, the issue seems to be with the user_agent. The geoapiExercises user agent has been in use for years and is likely blocked by the API. The Geopy installation docs also stress using a custom user agent for your app.

Could you try changing the user agent to another string? Additionally, please share the links to both your GitHub repo and app.

I was able to successfully deploy the app and have it return India with your code above (but changing the user agent to abcd and the following requirements.txt:


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.