Google-api-python-client: 'Http' object has no attribute 'close'

Created on 26 Sep 2020  路  8Comments  路  Source: googleapis/google-api-python-client

Environment details

  • OS type and version: ubuntu 16.04.6 LTS (4.15.0-1050-gcp)
  • Python version: 3.6.8
  • pip version: 3.6
  • google-api-python-client version: 1.7.1

  • Other dependency
    image

from apiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = conf.KEY_FILE_LOCATION

credentials = ServiceAccountCredentials.from_json_keyfile_name(
        KEY_FILE_LOCATION, SCOPES)

# Build the service object.
if version == 'v4':
    analytics = build('analyticsreporting', 'v4', credentials=credentials, cache_discovery=False)
elif version == 'v3':
    analytics = build('analytics', 'v3', credentials=credentials, cache_discovery=False)
return analytics

PS. KEY_FILE_LOCATION is a json key generated from GCP

Stack trace

  File "/home/dsu/ddt_dashboard/ddt_get_ga_report/lib/app.py", line 454, in get_report
    analyticsV3 = initialize_analyticsreporting('v3')
  File "/home/dsu/ddt_dashboard/ddt_get_ga_report/lib/app.py", line 117, in initialize_analyticsreporting
    analytics = build('analytics', 'v3', credentials=credentials, cache_discovery=False)
  File "/usr/local/lib/python3.6/dist-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/googleapiclient/discovery.py", line 300, in build
    discovery_http.close()
AttributeError: 'Http' object has no attribute 'close'

The code works fine on my local machine (win10).
Not sure if it is about package dependency or something else.

Any suggestions would be appreciated, thanks.

triage me

Most helpful comment

@frankShih

Having a look at httplib2 changelog, close() method appeared in v0.15.0

According your error report, you have version 0.12.0.

Please, upgrade 1st, then retry and report.
Thanks

All 8 comments

I'm facing the same problem.

C:\Python363\python.exe N:/matabares/PythonSnippets/demoGoogleDrive.py
Traceback (most recent call last):
File "N:/matabares/PythonSnippets/demoGoogleDrive.py", line 49, in
main()
File "N:/matabares/PythonSnippets/demoGoogleDrive.py", line 34, in main
service = build('drive', 'v3', credentials=creds)
File "C:\Python363\lib\site-packages\googleapiclient_helpers.py", line 134, in positional_wrapper
return wrapped(args, *kwargs)
File "C:\Python363\lib\site-packages\googleapiclient\discovery.py", line 300, in build
discovery_http.close()
AttributeError: 'Http' object has no attribute 'close'

Process finished with exit code 1

I've been developing a script for my company and today I also get that error. Yesterday it worked perfectly.

Mine is latest version: 1.12.2
Python3: 3.8.2

The error doesn't happen with version 1.12.1 (tried it using pipenv).

Hi, as said, in the other ticket, did you try to upgrade to the last version of httplib2 as well?
close() attribute belongs to http object from httplib2 library.
Maybe it was not existing in the version of the library you are currently using?

Hi, I just want to add that I've just updated from python3.7 to python3.8 a few moments ago and a script I had stopped working for the newer version.

I'm using Ubuntu 20.04, let me know if you need more info

Edit: Forgot to add, I've run pip3 install httplib2 and it was already satisfied with version 0.14.0

@frankShih

Having a look at httplib2 changelog, close() method appeared in v0.15.0

According your error report, you have version 0.12.0.

Please, upgrade 1st, then retry and report.
Thanks

That fixed it! Thanks you for you time

That fixed it! Thanks you for you time

1st time ever my feedback helps someone. Thanks to reply back ;) :+1:
Feeling proud now ;)

Fixed for me aswell.

google-api-python-client: 1.12.2
httplib2: 0.18.1

Was this page helpful?
0 / 5 - 0 ratings