Skip to content

Closing discovery item fails with AttributeError: 'Http' object has no attribute 'http' for Python 2 users #2610

Open
@wescpy

Description

@wescpy

The fix for this bug in googleapiclient/discovery.py needs to be backported to v1 for Python 2 users. Since I'm unable to reopen that bug, I had to file this new one instead.

Environment details

  • OS type and version: macos Ventura 13.7.6 (22H625)
  • Python version: Python 2.7.18
  • pip version: pip 20.3.4 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip (python 2.7)
  • google-api-python-client and httplib2 versions: pip show google-api-python-client httplib2
$ pip show google-api-python-client httplib2 | egrep "Nam|Ver|Req"
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.

Name: google-api-python-client
Version: 1.12.11
Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires: google-auth-httplib2, rsa, httplib2, six, google-auth, google-api-core, uritemplate
Required-by:

Name: httplib2
Version: 0.22.0
Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires: pyparsing
Required-by: oauth2client, google-auth-httplib2, google-api-python-client

Steps to reproduce

  1. Get a Python 2 installation or venv/virtualenv
  2. Install necessary libs with pip install -U pip google-api-python-client oauth2client
  3. Confirm libs installed with python -c "import googleapiclient, httplib2, oauth2client" (no errors or output)
  4. Create sample app (see 1046test.py below)
  5. Run sample app (output below in Stack trace)

Code example (1046test.py)

from googleapiclient import discovery
from httplib2 import Http

service = discovery.build('drive', 'v3', http=Http())
service.close()

Stack trace

$ python 1046test.py
Traceback (most recent call last):
  File "1046test.py", line 5, in <module>
    service.close()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/googleapiclient/discovery.py", line 1335, in close
    self._http.http.close()
AttributeError: 'Http' object has no attribute 'http'

Solution

Reuse/apply the same 5-char fix to discovery.py but to the latest v1 discovery.py so Python 2 users can access the same fix Python 3 users have.

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions