Skip to content

'Http' object has no attribute 'close' #1047

Closed

Description

@frankShih

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.

Activity

  1. matabares commented on Sep 26, 2020

    @matabares

    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

  2. jvalrog commented on Sep 26, 2020

    @jvalrog

    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).

  3. yohplala commented on Sep 26, 2020

    @yohplala

    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?

  4. lpinilla commented on Sep 26, 2020

    @lpinilla

    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

  5. yohplala commented on Sep 26, 2020

    @yohplala

    @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

  6. lpinilla commented on Sep 26, 2020

    @lpinilla

    That fixed it! Thanks you for you time

  7. yohplala commented on Sep 26, 2020

    @yohplala

    That fixed it! Thanks you for you time

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

  8. jvalrog commented on Sep 27, 2020

    @jvalrog

    Fixed for me aswell.

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

  9. Arszilla commented on Feb 18, 2021

    @Arszilla

    I should note that this issue persists even with httplib2 version 0.19.0:

    [...]
    
    "google-api-python-client": {
        "hashes": [
            "sha256:3c4c4ca46b5c21196bec7ee93453443e477d82cbfa79234d1ce0645f81170eaf",
            "sha256:f3b9684442eec2cfe9f9bb48e796ef919456b82142c7528c5fd527e5224f08bb"
        ],
        "index": "pypi",
        "version": "==1.12.8"
    },
    
    [...]
    
    "httplib2": {
        "hashes": [
            "sha256:749c32603f9bf16c1277f59531d502e8f1c2ca19901ae653b49c4ed698f0820e",
            "sha256:e0d428dad43c72dbce7d163b7753ffc7a39c097e6788ef10f4198db69b92f08e"
        ],
        "version": "==0.19.0"
    },
    
    [...]
    

    Update: I can confirm that this happens when using:

    from googleapiclient.discovery import build
    
    with build("youtube", "v3") as youtube:

    but not when using

    from googleapiclient.discovery import build
    
    youtube = build("youtube", "v3")
  10. austinweisgrau commented on Sep 10, 2021

    @austinweisgrau

    I'm seeing this issue as well with httplib2 0.19.0 and google-api-python-client 2.20.0

    from google.oauth2 import service_account
    from googleapiclient.discovery import build
    
    def authenticate_service():
        creds = service_account.Credentials.from_service_account_file(
            SERVICE_ACCOUNT_FILE, scopes=SCOPES)
    
        service = build('drive', 'v3', credentials=creds)
    
        return service
    

    here's the stack trace:

    ~/.local/lib/python3.8/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
        129                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
        130                     logger.warning(message)
    --> 131             return wrapped(*args, **kwargs)
        132 
        133         return positional_wrapper
    
    ~/.local/lib/python3.8/site-packages/googleapiclient/discovery.py in build(serviceName, version, http, discoveryServiceUrl, developerKey, model, requestBuilder, credentials, cache_discovery, cache, client_options, adc_cert_path, adc_key_path, num_retries, static_discovery)
        313     # and can safely close it
        314     if http is None:
    --> 315         discovery_http.close()
        316 
        317     if service is None:
    
    AttributeError: 'Http' object has no attribute 'close'
    
  11. austinweisgrau commented on Sep 10, 2021

    @austinweisgrau

    Nevermind, I've got httplib2==0.14.0 installed in /usr/lib/python3/dist-packages that was actually being called despite having an updated httplib2 in ~/.local/lib/python3/site-packages

  12. hungchiehchi commented on Mar 2, 2022

    @hungchiehchi

    Traceback (most recent call last):
    File "test_gcp.py", line 25, in
    lservice = build('language', 'v1beta1', developerKey=APIKEY)
    File "/usr/local/lib/python3.8/dist-packages/googleapiclient/_helpers.py", line 131, in positional_wrapper
    return wrapped(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/googleapiclient/discovery.py", line 321, in build
    discovery_http.close()
    AttributeError: 'Http' object has no attribute 'close'

    i've upgrade to httplib2 0.20.4 but still have this problem ..

  13. ben519 commented on Dec 9, 2022

    @ben519

    I needed to re-install google-api-python-client after upgrading httplib2 for the error to go away.

    pip install --upgrade httplib2
    pip install --upgrade google-api-python-client
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions