We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`TypeError` when trying to issue `BatchHttpRequest` when service was built using application default credentials
This issue is very similar to #211.  My team has an app-engine application that uses batch requests in the Gmail API.  After an upgrade of this client library, we started seeing failures:

```
...
  File "/base/data/home/apps/s~app-id/modname:version/path/to/my/code.py", line 241, in _user_method
    return batch_request.execute(http=self._http)
  File "/base/data/home/apps/s~app-id/modname:version/third_party/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/base/data/home/apps/s~app-id/modname:version/third_party/googleapiclient/http.py", line 1417, in execute
    self._execute(http, self._order, self._requests)
  File "/base/data/home/apps/s~app-id/modname:version/third_party/googleapiclient/http.py", line 1333, in _execute
    body = self._serialize_request(request)
  File "/base/data/home/apps/s~app-id/modname:version/third_party/googleapiclient/http.py", line 1204, in _serialize_request
    request.http.request.credentials.apply(headers)
  File "/base/data/home/apps/s~app-id/modname:version/third_party/oauth2client/client.py", line 558, in apply
    headers['Authorization'] = 'Bearer ' + self.access_token
TypeError: cannot concatenate 'str' and 'NoneType' objects
```

Our usage of this client library looks like the following:

```python
from googleapiclient.discovery import build
gmail_service = build('gmail', 'v1')  # Uses application credentials

...

authorized_http = user_credentials.authorize(httplib2.Http())  # Uses end user credentials

batch_request = gmail_service.new_batch_http_request()
batch_request.add(
    gmail_service.users().threads().get(id=thread_id, userId='me'),
    callback=callback,
    request_id=thread_id)

batch_request.execute(http=authorized_http)
```

The `gmail_service` is cached at the application level to avoid needing to do an API call for each request (which is why it ends up with the application credentials).  What I believe is happening is that

```py
gmail_service.users().threads().get(id=thread_id, userId='me')
```

ends up creating an `HttpRequest` that uses the same `http` that was used to construct `gmail_service` (i.e. the application credentials) and I believe that the application credentials have no `access_token`.  This results in the `TypeError` seen above.  The fix in [#232](https://github.com/google/google-api-python-client/pull/232/files) won't help (the `http` that is getting passed to `batch_request.execute` is valid).

It seems to me that the application of credentials in [_serialize_request](https://github.com/google/google-api-python-client/blob/master/googleapiclient/http.py#L1202) should be conditional on the credentials actually having an access token:

```python
if request.http is not None and hasattr(request.http.request,
    'credentials'):
    if request.http.request.credentials.access_token:
        request.http.request.credentials.apply(headers)
```

Otherwise, if the sub-request isn't authenticated then the authentication from the outer request should be used (at least, if the [gmail docs](https://developers.google.com/gmail/api/guides/batch) are any indicator):

> The HTTP headers for the outer batch request, except for the Content- headers such as Content-Type, apply to every request in the batch. If you specify a given HTTP header in both the outer request and an individual call, then the individual call header's value overrides the outer batch request header's value. The headers for an individual call apply only to that call.

> For example, if you provide an Authorization header for a specific call, then that header applies only to that call. If you provide an Authorization header for the outer request, then that header applies to all of the individual calls unless they override it with Authorization headers of their own.

--------

In the event that this behavior is actually working as intended or if my proposed fix isn't satisfactory and a real fix would be too difficult, a work-around to this issue is possible by updating the requests that you add to the batch with an appropriately authorized http instance.  i.e changing the above to:

```python

batch_request = gmail_service.new_batch_http_request()

request =  gmail_service.users().threads().get(id=thread_id, userId='me')
request.http = authorized_http  # explicitly set the authorization on the request.

batch_request.add(
    request,
    callback=callback,
    request_id=thread_id)

batch_request.execute(http=authorized_http)
```

Seems to fix the issue.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `googleapiclient/_auth.py`
Content:
```
1 # Copyright 2016 Google Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """Helpers for authentication using oauth2client or google-auth."""
16 
17 import httplib2
18 
19 try:
20     import google.auth
21     import google.auth.credentials
22     HAS_GOOGLE_AUTH = True
23 except ImportError:  # pragma: NO COVER
24     HAS_GOOGLE_AUTH = False
25 
26 try:
27     import google_auth_httplib2
28 except ImportError:  # pragma: NO COVER
29     google_auth_httplib2 = None
30 
31 try:
32     import oauth2client
33     import oauth2client.client
34     HAS_OAUTH2CLIENT = True
35 except ImportError:  # pragma: NO COVER
36     HAS_OAUTH2CLIENT = False
37 
38 
39 def default_credentials():
40     """Returns Application Default Credentials."""
41     if HAS_GOOGLE_AUTH:
42         credentials, _ = google.auth.default()
43         return credentials
44     elif HAS_OAUTH2CLIENT:
45         return oauth2client.client.GoogleCredentials.get_application_default()
46     else:
47         raise EnvironmentError(
48             'No authentication library is available. Please install either '
49             'google-auth or oauth2client.')
50 
51 
52 def with_scopes(credentials, scopes):
53     """Scopes the credentials if necessary.
54 
55     Args:
56         credentials (Union[
57             google.auth.credentials.Credentials,
58             oauth2client.client.Credentials]): The credentials to scope.
59         scopes (Sequence[str]): The list of scopes.
60 
61     Returns:
62         Union[google.auth.credentials.Credentials,
63             oauth2client.client.Credentials]: The scoped credentials.
64     """
65     if HAS_GOOGLE_AUTH and isinstance(
66             credentials, google.auth.credentials.Credentials):
67         return google.auth.credentials.with_scopes_if_required(
68             credentials, scopes)
69     else:
70         try:
71             if credentials.create_scoped_required():
72                 return credentials.create_scoped(scopes)
73             else:
74                 return credentials
75         except AttributeError:
76             return credentials
77 
78 
79 def authorized_http(credentials):
80     """Returns an http client that is authorized with the given credentials.
81 
82     Args:
83         credentials (Union[
84             google.auth.credentials.Credentials,
85             oauth2client.client.Credentials]): The credentials to use.
86 
87     Returns:
88         Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An
89             authorized http client.
90     """
91     from googleapiclient.http import build_http
92 
93     if HAS_GOOGLE_AUTH and isinstance(
94             credentials, google.auth.credentials.Credentials):
95         if google_auth_httplib2 is None:
96             raise ValueError(
97                 'Credentials from google.auth specified, but '
98                 'google-api-python-client is unable to use these credentials '
99                 'unless google-auth-httplib2 is installed. Please install '
100                 'google-auth-httplib2.')
101         return google_auth_httplib2.AuthorizedHttp(credentials,
102                                                    http=build_http())
103     else:
104         return credentials.authorize(build_http())
105 
106 
107 def refresh_credentials(credentials):
108     # Refresh must use a new http instance, as the one associated with the
109     # credentials could be a AuthorizedHttp or an oauth2client-decorated
110     # Http instance which would cause a weird recursive loop of refreshing
111     # and likely tear a hole in spacetime.
112     refresh_http = httplib2.Http()
113     if HAS_GOOGLE_AUTH and isinstance(
114             credentials, google.auth.credentials.Credentials):
115         request = google_auth_httplib2.Request(refresh_http)
116         return credentials.refresh(request)
117     else:
118         return credentials.refresh(refresh_http)
119 
120 
121 def apply_credentials(credentials, headers):
122     # oauth2client and google-auth have the same interface for this.
123     return credentials.apply(headers)
124 
125 
126 def is_valid(credentials):
127     if HAS_GOOGLE_AUTH and isinstance(
128             credentials, google.auth.credentials.Credentials):
129         return credentials.valid
130     else:
131         return not credentials.access_token_expired
132 
133 
134 def get_credentials_from_http(http):
135     if http is None:
136         return None
137     elif hasattr(http.request, 'credentials'):
138         return http.request.credentials
139     elif (hasattr(http, 'credentials')
140           and not isinstance(http.credentials, httplib2.Credentials)):
141         return http.credentials
142     else:
143         return None
144
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/googleapiclient/_auth.py b/googleapiclient/_auth.py
--- a/googleapiclient/_auth.py
+++ b/googleapiclient/_auth.py
@@ -120,6 +120,8 @@
 
 def apply_credentials(credentials, headers):
     # oauth2client and google-auth have the same interface for this.
+    if not is_valid(credentials):
+        refresh_credentials(credentials)
     return credentials.apply(headers)
 
 
@@ -128,7 +130,9 @@
             credentials, google.auth.credentials.Credentials):
         return credentials.valid
     else:
-        return not credentials.access_token_expired
+        return (
+            credentials.access_token is not None and
+            not credentials.access_token_expired)
 
 
 def get_credentials_from_http(http):

{"golden_diff": "diff --git a/googleapiclient/_auth.py b/googleapiclient/_auth.py\n--- a/googleapiclient/_auth.py\n+++ b/googleapiclient/_auth.py\n@@ -120,6 +120,8 @@\n \n def apply_credentials(credentials, headers):\n     # oauth2client and google-auth have the same interface for this.\n+    if not is_valid(credentials):\n+        refresh_credentials(credentials)\n     return credentials.apply(headers)\n \n \n@@ -128,7 +130,9 @@\n             credentials, google.auth.credentials.Credentials):\n         return credentials.valid\n     else:\n-        return not credentials.access_token_expired\n+        return (\n+            credentials.access_token is not None and\n+            not credentials.access_token_expired)\n \n \n def get_credentials_from_http(http):\n", "issue": "`TypeError` when trying to issue `BatchHttpRequest` when service was built using application default credentials\nThis issue is very similar to #211.  My team has an app-engine application that uses batch requests in the Gmail API.  After an upgrade of this client library, we started seeing failures:\r\n\r\n```\r\n...\r\n  File \"/base/data/home/apps/s~app-id/modname:version/path/to/my/code.py\", line 241, in _user_method\r\n    return batch_request.execute(http=self._http)\r\n  File \"/base/data/home/apps/s~app-id/modname:version/third_party/oauth2client/_helpers.py\", line 133, in positional_wrapper\r\n    return wrapped(*args, **kwargs)\r\n  File \"/base/data/home/apps/s~app-id/modname:version/third_party/googleapiclient/http.py\", line 1417, in execute\r\n    self._execute(http, self._order, self._requests)\r\n  File \"/base/data/home/apps/s~app-id/modname:version/third_party/googleapiclient/http.py\", line 1333, in _execute\r\n    body = self._serialize_request(request)\r\n  File \"/base/data/home/apps/s~app-id/modname:version/third_party/googleapiclient/http.py\", line 1204, in _serialize_request\r\n    request.http.request.credentials.apply(headers)\r\n  File \"/base/data/home/apps/s~app-id/modname:version/third_party/oauth2client/client.py\", line 558, in apply\r\n    headers['Authorization'] = 'Bearer ' + self.access_token\r\nTypeError: cannot concatenate 'str' and 'NoneType' objects\r\n```\r\n\r\nOur usage of this client library looks like the following:\r\n\r\n```python\r\nfrom googleapiclient.discovery import build\r\ngmail_service = build('gmail', 'v1')  # Uses application credentials\r\n\r\n...\r\n\r\nauthorized_http = user_credentials.authorize(httplib2.Http())  # Uses end user credentials\r\n\r\nbatch_request = gmail_service.new_batch_http_request()\r\nbatch_request.add(\r\n    gmail_service.users().threads().get(id=thread_id, userId='me'),\r\n    callback=callback,\r\n    request_id=thread_id)\r\n\r\nbatch_request.execute(http=authorized_http)\r\n```\r\n\r\nThe `gmail_service` is cached at the application level to avoid needing to do an API call for each request (which is why it ends up with the application credentials).  What I believe is happening is that\r\n\r\n```py\r\ngmail_service.users().threads().get(id=thread_id, userId='me')\r\n```\r\n\r\nends up creating an `HttpRequest` that uses the same `http` that was used to construct `gmail_service` (i.e. the application credentials) and I believe that the application credentials have no `access_token`.  This results in the `TypeError` seen above.  The fix in [#232](https://github.com/google/google-api-python-client/pull/232/files) won't help (the `http` that is getting passed to `batch_request.execute` is valid).\r\n\r\nIt seems to me that the application of credentials in [_serialize_request](https://github.com/google/google-api-python-client/blob/master/googleapiclient/http.py#L1202) should be conditional on the credentials actually having an access token:\r\n\r\n```python\r\nif request.http is not None and hasattr(request.http.request,\r\n    'credentials'):\r\n    if request.http.request.credentials.access_token:\r\n        request.http.request.credentials.apply(headers)\r\n```\r\n\r\nOtherwise, if the sub-request isn't authenticated then the authentication from the outer request should be used (at least, if the [gmail docs](https://developers.google.com/gmail/api/guides/batch) are any indicator):\r\n\r\n> The HTTP headers for the outer batch request, except for the Content- headers such as Content-Type, apply to every request in the batch. If you specify a given HTTP header in both the outer request and an individual call, then the individual call header's value overrides the outer batch request header's value. The headers for an individual call apply only to that call.\r\n\r\n> For example, if you provide an Authorization header for a specific call, then that header applies only to that call. If you provide an Authorization header for the outer request, then that header applies to all of the individual calls unless they override it with Authorization headers of their own.\r\n\r\n--------\r\n\r\nIn the event that this behavior is actually working as intended or if my proposed fix isn't satisfactory and a real fix would be too difficult, a work-around to this issue is possible by updating the requests that you add to the batch with an appropriately authorized http instance.  i.e changing the above to:\r\n\r\n```python\r\n\r\nbatch_request = gmail_service.new_batch_http_request()\r\n\r\nrequest =  gmail_service.users().threads().get(id=thread_id, userId='me')\r\nrequest.http = authorized_http  # explicitly set the authorization on the request.\r\n\r\nbatch_request.add(\r\n    request,\r\n    callback=callback,\r\n    request_id=thread_id)\r\n\r\nbatch_request.execute(http=authorized_http)\r\n```\r\n\r\nSeems to fix the issue.\n", "before_files": [{"content": "# Copyright 2016 Google Inc. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Helpers for authentication using oauth2client or google-auth.\"\"\"\n\nimport httplib2\n\ntry:\n    import google.auth\n    import google.auth.credentials\n    HAS_GOOGLE_AUTH = True\nexcept ImportError:  # pragma: NO COVER\n    HAS_GOOGLE_AUTH = False\n\ntry:\n    import google_auth_httplib2\nexcept ImportError:  # pragma: NO COVER\n    google_auth_httplib2 = None\n\ntry:\n    import oauth2client\n    import oauth2client.client\n    HAS_OAUTH2CLIENT = True\nexcept ImportError:  # pragma: NO COVER\n    HAS_OAUTH2CLIENT = False\n\n\ndef default_credentials():\n    \"\"\"Returns Application Default Credentials.\"\"\"\n    if HAS_GOOGLE_AUTH:\n        credentials, _ = google.auth.default()\n        return credentials\n    elif HAS_OAUTH2CLIENT:\n        return oauth2client.client.GoogleCredentials.get_application_default()\n    else:\n        raise EnvironmentError(\n            'No authentication library is available. Please install either '\n            'google-auth or oauth2client.')\n\n\ndef with_scopes(credentials, scopes):\n    \"\"\"Scopes the credentials if necessary.\n\n    Args:\n        credentials (Union[\n            google.auth.credentials.Credentials,\n            oauth2client.client.Credentials]): The credentials to scope.\n        scopes (Sequence[str]): The list of scopes.\n\n    Returns:\n        Union[google.auth.credentials.Credentials,\n            oauth2client.client.Credentials]: The scoped credentials.\n    \"\"\"\n    if HAS_GOOGLE_AUTH and isinstance(\n            credentials, google.auth.credentials.Credentials):\n        return google.auth.credentials.with_scopes_if_required(\n            credentials, scopes)\n    else:\n        try:\n            if credentials.create_scoped_required():\n                return credentials.create_scoped(scopes)\n            else:\n                return credentials\n        except AttributeError:\n            return credentials\n\n\ndef authorized_http(credentials):\n    \"\"\"Returns an http client that is authorized with the given credentials.\n\n    Args:\n        credentials (Union[\n            google.auth.credentials.Credentials,\n            oauth2client.client.Credentials]): The credentials to use.\n\n    Returns:\n        Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An\n            authorized http client.\n    \"\"\"\n    from googleapiclient.http import build_http\n\n    if HAS_GOOGLE_AUTH and isinstance(\n            credentials, google.auth.credentials.Credentials):\n        if google_auth_httplib2 is None:\n            raise ValueError(\n                'Credentials from google.auth specified, but '\n                'google-api-python-client is unable to use these credentials '\n                'unless google-auth-httplib2 is installed. Please install '\n                'google-auth-httplib2.')\n        return google_auth_httplib2.AuthorizedHttp(credentials,\n                                                   http=build_http())\n    else:\n        return credentials.authorize(build_http())\n\n\ndef refresh_credentials(credentials):\n    # Refresh must use a new http instance, as the one associated with the\n    # credentials could be a AuthorizedHttp or an oauth2client-decorated\n    # Http instance which would cause a weird recursive loop of refreshing\n    # and likely tear a hole in spacetime.\n    refresh_http = httplib2.Http()\n    if HAS_GOOGLE_AUTH and isinstance(\n            credentials, google.auth.credentials.Credentials):\n        request = google_auth_httplib2.Request(refresh_http)\n        return credentials.refresh(request)\n    else:\n        return credentials.refresh(refresh_http)\n\n\ndef apply_credentials(credentials, headers):\n    # oauth2client and google-auth have the same interface for this.\n    return credentials.apply(headers)\n\n\ndef is_valid(credentials):\n    if HAS_GOOGLE_AUTH and isinstance(\n            credentials, google.auth.credentials.Credentials):\n        return credentials.valid\n    else:\n        return not credentials.access_token_expired\n\n\ndef get_credentials_from_http(http):\n    if http is None:\n        return None\n    elif hasattr(http.request, 'credentials'):\n        return http.request.credentials\n    elif (hasattr(http, 'credentials')\n          and not isinstance(http.credentials, httplib2.Credentials)):\n        return http.credentials\n    else:\n        return None\n", "path": "googleapiclient/_auth.py"}], "after_files": [{"content": "# Copyright 2016 Google Inc. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Helpers for authentication using oauth2client or google-auth.\"\"\"\n\nimport httplib2\n\ntry:\n    import google.auth\n    import google.auth.credentials\n    HAS_GOOGLE_AUTH = True\nexcept ImportError:  # pragma: NO COVER\n    HAS_GOOGLE_AUTH = False\n\ntry:\n    import google_auth_httplib2\nexcept ImportError:  # pragma: NO COVER\n    google_auth_httplib2 = None\n\ntry:\n    import oauth2client\n    import oauth2client.client\n    HAS_OAUTH2CLIENT = True\nexcept ImportError:  # pragma: NO COVER\n    HAS_OAUTH2CLIENT = False\n\n\ndef default_credentials():\n    \"\"\"Returns Application Default Credentials.\"\"\"\n    if HAS_GOOGLE_AUTH:\n        credentials, _ = google.auth.default()\n        return credentials\n    elif HAS_OAUTH2CLIENT:\n        return oauth2client.client.GoogleCredentials.get_application_default()\n    else:\n        raise EnvironmentError(\n            'No authentication library is available. Please install either '\n            'google-auth or oauth2client.')\n\n\ndef with_scopes(credentials, scopes):\n    \"\"\"Scopes the credentials if necessary.\n\n    Args:\n        credentials (Union[\n            google.auth.credentials.Credentials,\n            oauth2client.client.Credentials]): The credentials to scope.\n        scopes (Sequence[str]): The list of scopes.\n\n    Returns:\n        Union[google.auth.credentials.Credentials,\n            oauth2client.client.Credentials]: The scoped credentials.\n    \"\"\"\n    if HAS_GOOGLE_AUTH and isinstance(\n            credentials, google.auth.credentials.Credentials):\n        return google.auth.credentials.with_scopes_if_required(\n            credentials, scopes)\n    else:\n        try:\n            if credentials.create_scoped_required():\n                return credentials.create_scoped(scopes)\n            else:\n                return credentials\n        except AttributeError:\n            return credentials\n\n\ndef authorized_http(credentials):\n    \"\"\"Returns an http client that is authorized with the given credentials.\n\n    Args:\n        credentials (Union[\n            google.auth.credentials.Credentials,\n            oauth2client.client.Credentials]): The credentials to use.\n\n    Returns:\n        Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An\n            authorized http client.\n    \"\"\"\n    from googleapiclient.http import build_http\n\n    if HAS_GOOGLE_AUTH and isinstance(\n            credentials, google.auth.credentials.Credentials):\n        if google_auth_httplib2 is None:\n            raise ValueError(\n                'Credentials from google.auth specified, but '\n                'google-api-python-client is unable to use these credentials '\n                'unless google-auth-httplib2 is installed. Please install '\n                'google-auth-httplib2.')\n        return google_auth_httplib2.AuthorizedHttp(credentials,\n                                                   http=build_http())\n    else:\n        return credentials.authorize(build_http())\n\n\ndef refresh_credentials(credentials):\n    # Refresh must use a new http instance, as the one associated with the\n    # credentials could be a AuthorizedHttp or an oauth2client-decorated\n    # Http instance which would cause a weird recursive loop of refreshing\n    # and likely tear a hole in spacetime.\n    refresh_http = httplib2.Http()\n    if HAS_GOOGLE_AUTH and isinstance(\n            credentials, google.auth.credentials.Credentials):\n        request = google_auth_httplib2.Request(refresh_http)\n        return credentials.refresh(request)\n    else:\n        return credentials.refresh(refresh_http)\n\n\ndef apply_credentials(credentials, headers):\n    # oauth2client and google-auth have the same interface for this.\n    if not is_valid(credentials):\n        refresh_credentials(credentials)\n    return credentials.apply(headers)\n\n\ndef is_valid(credentials):\n    if HAS_GOOGLE_AUTH and isinstance(\n            credentials, google.auth.credentials.Credentials):\n        return credentials.valid\n    else:\n        return (\n            credentials.access_token is not None and\n            not credentials.access_token_expired)\n\n\ndef get_credentials_from_http(http):\n    if http is None:\n        return None\n    elif hasattr(http.request, 'credentials'):\n        return http.request.credentials\n    elif (hasattr(http, 'credentials')\n          and not isinstance(http.credentials, httplib2.Credentials)):\n        return http.credentials\n    else:\n        return None\n", "path": "googleapiclient/_auth.py"}]}