I am building an app using streamlit. That app requires users’ public IP addresses for further processing. I have used geocoder
module to get the IP address. And it is working when I run the streamlit app in localhost. This was the code I was using.
import geocoder
import streamlit as st
location = geocoder.ip("me")
ip_address = location.ip
ip_url = f"https://reallyfreegeoip.org/json/{ip_address}"
r = requests.get(ip_url)
ip_details = r.json()
county_name = ip_details["country_name"]
st.write(county_name)
But as soon as I deploy the app in streamlit share it does not work. Instead of working I am getting the below error in the log, and the app crashes. The app does not load at all.
Status code 429 from http://ipinfo.io/json: ERROR - 429 Client Error: Too Many Requests for url: http://ipinfo.io/json
So, I changed the method for getting the IP address. This time I used the below code to get the IP address, and it is again working well in the localhost.
import requests
import streamlit as st
ip = requests.get('https://api64.ipify.org').text
ip_url = f"https://reallyfreegeoip.org/json/{ip}"
r = requests.get(ip_url)
ip_details = r.json()
county_name = ip_details["country_name"]
st.write(county_name)
But as soon as I deploy the app in the streamlit share. It is getting the United States IP only. This time no error message like the previous one.