Forums

Static IP

I need my app to run on a static IP address. It needs to talk to an external API whose owners want to whitelist my app's IP address.

Is this possible on PythonAnywhere?

Thanks much.

Vikram

No, it's not. The source IP address can change for a whole number of reasons and they're not always predictable.

Figured that was probably the case but thought I'd ask.

Thanks.

Are there any suggested workarounds for this type of problem?

I am also very interested in this as well. Because MongoDB is not an option I need to connect to a remote database that usually requires a whitelist IP address.

So you can definitely connect to a third party mongdodb service as a paid user (eg: mongolabs etc), that doesn't have IP restrictions. See this for how to setup the mongo cli etc as well.

It looks like sites like MongoDB Atlas you can bypass the IP restriction by allowing all (0.0.0.0 to whitelist). This is fine for Dev but I need to see how much it bothers me in the production environment.

Seems like a static ip should be a feature you could buy for some small amount of $...

I have a similar conundrum...

I have a pythonanywhere script that uses a API get request with a key that is generated for a specific ip. The pythonanywhere ip's change and you don't know what it will be. I have been using a proxy and specifying the proxy in the get request with a key generated for the known proxy ip (which i get from us-proxy.org) and it works fine. But those proxies go up and down.

I have a computer running linux/ubuntu at home and am looking into using tinyproxy to run a proxy server. However, my initial attempts haven't worked. I think I'm doing something wrong with the config.

Wondering if anyone else has done something similar?

no-one in the office has configured tinyproxy i'm afraid... maybe someone else out there? you might also try posting this question elsewhere...

in the meantime i'll note a +1 for the "static ip as a service", but I have to say that feels like a lot of work for us to implement, for quite a niche market, so i'm not sure it's likely to get worked on in the short term...

Thanks for input harry. I don't expect pa to implement a static ip service, I can see why that would be complicated with low utility. Was just wondering if anyone else had developed a similar or different work around. I'm also asking for help with the tinyproxy elsewhere. Besides, it's a good project for me to work on ;)

You guys do a great job at pa! Thank you!

well thank you kindly :)

Is there a range of IPs we can use for PA? Would be nice to not have to open it to the entire internet.

The range of IPs would be "all AWS IPs". Although that's not actually the entire internet, from a security standpoint, it may as well be.

Got it, wasn't sure if AWS had allotted you some range, thanks.

Coincidentally, I was talking to one of our other customers the other day and they said they were using a static-IP-as-a-service with PythonAnywhere -- it's called Statica and it's from a company called QuotaGuard. They mentioned it in the context that it wasn't working for a specific use case they had (PyODBC to a remote Microsoft SQL Server instance -- pymssql was working, but not PyODBC) but maybe your use case would work. That said, it's not super-cheap -- $19/month for the cheapest plan.

Hmm, not sure on effort, but maybe some customers would buy access to an outgoing proxy run by PythonAnywhere? You could ensure that only your instances connected to it and the IP would be static to the API.

Looking at using Mongodb Atlas and running into this today.

Would you be able to share roughly how the other customer set this up? I actually have the exact same need (static IP to access a remote SQL Server). I see on Statica's site how to make requests thru a proxy, but it's unclear how to connect to a database.

are you accessing the database using the console command "mysql" etc? or doing it through a python script? or through a web framework?

Hey Conrad - I'm using SQLAlchemy (within a Flask app), so:

    fullConnectionString =  s['db_type'] + '://' + s['username'] + ':' + str(password) + '@' + \
        s['host'] + '/' + s['database']
    db = sqlalchemy.create_engine(fullConnectionString)

Take a look at this forum discussion.

Try setting the environment variable to the statica url, and then adding the static IP you get allocated to your whitelist.

Yeah, that works for requests and other libraries, but it doesn't seem to work for database connections. I just tested it out for an HTTP request and it works fine, but it doesn't seem to change the IP that a database connection request is coming from.

Yeah, that works for requests and other libraries, but it doesn't seem to work for database connections. I just tested it out for an HTTP request and it works fine, but it doesn't seem to change the IP that a database connection request is coming from.

Hmm, so it's from a web app. That might be a bit trickier than the use case the other people had; they were running stuff in scheduled tasks and from consoles, where you can run your code using a wrapper script that wraps all network access transparently (something like quotaguardwrapper python myscript.py) -- but of course in a web app, you can't specify the command line (because it's actually running inside a uWSGI plugin).

Maybe the Statica tech support will be able to suggest how to do it in a situation where you're accessing a database, but can't control the command line?

Thanks Gile, running from a scheduled task would actually be fine for me as well, could you give a little more info on how that would work? Not completey sure what you mean by quotaguardwrapper python myscript.py

This QuotaGuard help page should explain what to do -- in particular, the section titled "Installing the QuotaGuard Static wrapper". But if there's anything unclear after you've tried that out, do let us know.

There's apparently a pa help page on this topic. I hadn't see it before so I thought I'd share.

+1 for this request. When doing this myself on AWS I had to go through the process of setting up a few subnets to have my flask app have an outbound IP

Thanks -- I've upvoted the item on our to-do list. The stuff on the help page might be useful in the meantime, though -- we've added some new options recently.

Thanks! I've created a QuotaGuard account, but it looks like their docs are mainly around Node.js/database connections. Like mritchie above, I'm using sqlalchemy for my webapp to talk to a redshift database (which requires a whitelabeled IP). Unlike him, this isn't a scheduled task but a user-generated query, so I'm looking for something that can work in-app without a wrapper. I'd be interested if you know of any existing pa customers that have done this. Contacted QuotaGuard's customer support to see if they have any guidance as well.

Seems like they have a python quickstart guide which shows you how to do the static IP proxying in app?

Yeah, but that only works on HTTPS calls, not database connections. Talking to their support team, they don't currently have a solution for pa apps connecting to databases via a static, whitelisted IP.

That's because you're a free user. Database connections will only work for paid accounts.

Chrome Directed my IP problem not working in the Chrome browser

many of server provider there own IP address what is my IP address in pythonanywhere

Namecheap config is ok. properly work on firefox, not work on chrome. give me my IP addressenter image description here

Not working: http://b2bleadhut.com/ Working: http://www.b2bleadhut.com/ enter image description here

The IP address of your site can change without warning. Unless you know exactly what you're doing, you should not use an IP address for a PythonAnywhere web app.

See our help page on how to use naked domains with PythonAnywhere.

I need static IP of my web app to whitelist on my Microsoft Exchange online server so that I can use the server to send emails, I looked at https://www.quotaguard.com/docs/language-platform/python/python-anywhere-static-ip/ but it is even more confusing as I am not using it for database connection. Is there anyone who has done this for my similar use case. Has anyone configured static IP on Quotaguard. It would really help me a lot

See https://help.pythonanywhere.com/pages/StaticIPForExternalAllowlists/