Don't rely on SERVER_SOFTWARE being set for AppEngine
MODIFY
src/urllib3/contrib/_appengine_environ.py
src/urllib3/contrib/_appengine_environ.py
@@ -6,27 +6,31 @@ import os
def is_appengine():
- return is_local_appengine() or is_prod_appengine() or is_prod_appengine_mvms()
+ return "APPENGINE_RUNTIME" in os.environ
def is_appengine_sandbox():
- return is_appengine() and not is_prod_appengine_mvms()
+ """Reports if the app is running in the first generation sandbox.
+
+ The second generation runtimes are technically still in a sandbox, but it
+ is much less restrictive, so generally you shouldn't need to check for it.
+ see https://cloud.google.com/appengine/docs/standard/runtimes
+ """
+ return is_appengine() and os.environ["APPENGINE_RUNTIME"] == "python27"
def is_local_appengine():
- return (
- "APPENGINE_RUNTIME" in os.environ
- and "Development/" in os.environ["SERVER_SOFTWARE"]
+ return is_appengine() and os.environ.get("SERVER_SOFTWARE", "").startswith(
+ "Development/"
)
def is_prod_appengine():
- return (
- "APPENGINE_RUNTIME" in os.environ
- and "Google App Engine/" in os.environ["SERVER_SOFTWARE"]
- and not is_prod_appengine_mvms()
+ return is_appengine() and os.environ.get("SERVER_SOFTWARE", "").startswith(
+ "Google App Engine/"
)
def is_prod_appengine_mvms():
- return os.environ.get("GAE_VM", False) == "true"
+ """Deprecated."""
+ return False

MODIFY
src/urllib3/contrib/appengine.py
src/urllib3/contrib/appengine.py
@@ -108,13 +108,6 @@ class AppEngineManager(RequestMethods):
"URLFetch is not available in this environment."
)
- if is_prod_appengine_mvms():
- raise AppEnginePlatformError(
- "Use normal urllib3.PoolManager instead of AppEngineManager"
- "on Managed VMs, as using URLFetch is not necessary in "
- "this environment."
- )
-
warnings.warn(
"urllib3 is using URLFetch on Google App Engine sandbox instead "
"of sockets. To use sockets directly instead of URLFetch see "

Don't rely on SERVER_SOFTWARE being set for AppEngine (#1704)