Skip to content

Commit 79e81f9

Browse files
zevdgsethmlarson
authored andcommitted
Don't rely on SERVER_SOFTWARE being set for AppEngine (urllib3#1704)
1 parent cef15a1 commit 79e81f9

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/urllib3/contrib/_appengine_environ.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,31 @@
66

77

88
def is_appengine():
9-
return is_local_appengine() or is_prod_appengine() or is_prod_appengine_mvms()
9+
return "APPENGINE_RUNTIME" in os.environ
1010

1111

1212
def is_appengine_sandbox():
13-
return is_appengine() and not is_prod_appengine_mvms()
13+
"""Reports if the app is running in the first generation sandbox.
14+
15+
The second generation runtimes are technically still in a sandbox, but it
16+
is much less restrictive, so generally you shouldn't need to check for it.
17+
see https://cloud.google.com/appengine/docs/standard/runtimes
18+
"""
19+
return is_appengine() and os.environ["APPENGINE_RUNTIME"] == "python27"
1420

1521

1622
def is_local_appengine():
17-
return (
18-
"APPENGINE_RUNTIME" in os.environ
19-
and "Development/" in os.environ["SERVER_SOFTWARE"]
23+
return is_appengine() and os.environ.get("SERVER_SOFTWARE", "").startswith(
24+
"Development/"
2025
)
2126

2227

2328
def is_prod_appengine():
24-
return (
25-
"APPENGINE_RUNTIME" in os.environ
26-
and "Google App Engine/" in os.environ["SERVER_SOFTWARE"]
27-
and not is_prod_appengine_mvms()
29+
return is_appengine() and os.environ.get("SERVER_SOFTWARE", "").startswith(
30+
"Google App Engine/"
2831
)
2932

3033

3134
def is_prod_appengine_mvms():
32-
return os.environ.get("GAE_VM", False) == "true"
35+
"""Deprecated."""
36+
return False

src/urllib3/contrib/appengine.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ def __init__(
108108
"URLFetch is not available in this environment."
109109
)
110110

111-
if is_prod_appengine_mvms():
112-
raise AppEnginePlatformError(
113-
"Use normal urllib3.PoolManager instead of AppEngineManager"
114-
"on Managed VMs, as using URLFetch is not necessary in "
115-
"this environment."
116-
)
117-
118111
warnings.warn(
119112
"urllib3 is using URLFetch on Google App Engine sandbox instead "
120113
"of sockets. To use sockets directly instead of URLFetch see "

0 commit comments

Comments
 (0)