Repository: urllib3/urllib3

Issue:
contrib/_appengine_environ.py KeyError SERVER_SOFTWARE
https://github.com/urllib3/urllib3/blob/master/src/urllib3/contrib/_appengine_environ.py

In the development environment, the variable SERVER_SOFTWARE is sometimes not set, so the query should read as follows:

`os.environ.get('SERVER_SOFTWARE', '').startswith('Development')`

```
def is_local_appengine():
    return ('APPENGINE_RUNTIME' in os.environ and
            os.environ.get('SERVER_SOFTWARE', '').startswith('Development'))


def is_prod_appengine():
    return ('APPENGINE_RUNTIME' in os.environ and
            not os.environ.get('SERVER_SOFTWARE', '').startswith('Development') and
            not is_prod_appengine_mvms())
```


Discussion:
I would accept a PR that makes this change. cc: @theacodes 
Yeah, fine with me. I'd be curious to know when the local server doesn't set the `SERVER_SOFTWARE` and what effect that has on detection.
The Travis CI build could not complete ...
Any innovations here? @pquentin @theacodes 
I just ran into this bug, (simplified reproduction of how I ran into it https://repl.it/repls/ThinSpatialNumerator) and was about to submit a fix much like the two that have already been proposed.

There is some new, and possibly relevant information.  This function

```python
def is_prod_appengine_mvms():
    return os.environ.get('GAE_VM', False) == 'true'
```
seems to always returns False now.

App Engine stopped setting this variable and [removed it from their PHP docs](https://github.com/GoogleCloudPlatform/getting-started-php/pull/200/files) (I couldn't find any references to it in the python docs).

It looks like the reasons the original CL never made it in seem to be because they didn't work quite right on flex, but since the flex check isn't working anymore anyway, and no one seems to be complaining about it, I suggest we move forward with the fix now.

Resolving patch:
diff --git a/src/urllib3/contrib/_appengine_environ.py b/src/urllib3/contrib/_appengine_environ.py
--- a/src/urllib3/contrib/_appengine_environ.py
+++ b/src/urllib3/contrib/_appengine_environ.py
@@ -6,27 +6,31 @@
 
 
 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
diff --git a/src/urllib3/contrib/appengine.py b/src/urllib3/contrib/appengine.py
--- a/src/urllib3/contrib/appengine.py
+++ b/src/urllib3/contrib/appengine.py
@@ -108,13 +108,6 @@ def __init__(
                 "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 "


Test patch: