PythonAnywhere 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.