Forums

IP address changes when using pythonAnywhere

Hey All,

My webapp uses a third party ip locator API that needs the user's IP address to extract the city of the user. The API is embedded in my views.py file. When im running the django project on localhost, its showing my IP and city just fine, the way it should. However, when i running the project on pythonAnywhere( as a paying user ) im being allocated an IP from Ashburn, USA. That is incorrect as i am not logging in from Ashburn. User's city plays a major role in my code therefore with the wrong city, it just breaks everything. I have tried with different API providers but i get the same city when hitting them through pythonAnywhere, Ashburn.

Any solution would be really appreciated since this will be my first webapp. thank you!

Is it about location of the ip where your web app is running? That would whatever location that is shown for our servers.

Hey fjl, thanks for replying! I wanted to get the IP address of the user, not from where the web app is running. For this purpose i used ipapi service (https://ipapi.co/). I am a newbie, so if there's a flaw with my approach kindly guide me so that i can fix it. Thank you!

How do you get that ip address to check?

This is the API that i use to get the user's IP address: https://api64.ipify.org?format=json So basically, when the user clicks the submit button on my webpage, this API is hit in the background which then returns a JSON object through which the IP is extracted.

You should be able to get the user IP address directly from the request -- check the docs of the framework you use for your web app on how to get it.

Damn, it worked. Since i use Django, it was pretty easy to find it on the web. Looks like i dont have to use an API separately just tog et the IP. for that i can use a simple method from Django. Thanks a lot guys, appreciate it!

Glad to hear you solved it!