Forums

How to check whether your account is on the EU or the global site using Python

I'd like to run the same code on both the EU and the global site, but the code should behave differently in the two cases. What method would you recommend to check the location of the account that runs the code?

socket.gethostname()

seems to give a hostname that contains euconsole on an EU account and liveconsole on a global account. But I don't know how dependable that is as a long-term solution.

Or you could use os.environ["PYTHONANYWHERE_SITE"] which would return www.pythonanywhere.com or eu.pythonanywhere.com.

That sounds like a more appropriate solution. Thanks!