0

I am using an API to get the IP address of users when loading the Web Application to forward them info based on their location. However, I am getting the location of the AWS server and not the clients. By the way I am using Heroku. Here is the code below.


ipCall = requests.get('https://ip.seeip.org/jsonip?').content
ldata = json.loads(ipCall)
ip = ldata['ip']


ipLocate = requests.get(f'http://ip-api.com/json/{ip}').content
jdata = json.loads(ipLocate)
state = jdata['regionName']
locationFilt = jdata['city']


Here is the output on the web page: Location: Ashburn, VA. This is the location of the AWS server and not the clients.

  • To the best of my knowledge, Amazon doesn't let you know the IP of the original client, and there's no reason for you to know it. This page https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/example-function-add-true-client-ip-header.html shows how a client might *optionally* include their own IP in the header. – Frank Yellin Feb 23 '22 at 18:21
  • 2
    Check HTTP header: X-Forwarded-For ([Heroku headers doc](https://devcenter.heroku.com/articles/http-routing#heroku-headers)). – jarmod Feb 23 '22 at 18:21
  • Related: https://stackoverflow.com/questions/16558869/getting-ip-address-of-client – Code-Apprentice Feb 23 '22 at 18:25
  • Nice piece of code. I get state=`England` and locationFilt = `my city` so it looks good. – D.L Feb 23 '22 at 21:33

0 Answers0