You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Closing discovery item fails with AttributeError: 'Http' object has no attribute 'http' #1046
Hey @ghaithbilbeisi, could you show more of the stack trace?
From discussion in #1047 it looks like the issue is the low version of httplib2. I also see that this wouldn't work correctly if you were passing in your own httplib2 object (in that case it should just be self._http.close()).
Using the following authenticate and build_drive methods:
defauthenticate(secret):
""" Returns an oauth credentials object using the given secret, or stored credentials if available. """SCOPES='https://www.googleapis.com/auth/drive.readonly'store=file.Storage('storage.json')
creds=store.get()
ifnotcredsorcreds.invalid:
flow=client.flow_from_clientsecrets(secret, SCOPES)
creds=tools.run_flow(flow, store)
returncredsdefbuild_drive(creds):
try:
drive=discovery.build('drive', 'v3', credentials=creds)#http=creds.authorize(Http()))except:
drive=Nonereturndrive
Running this with google-api-python-client 1.12.3, httplib2 0.18.1, and python 3.8.3 gives the following error:
Traceback (most recent call last):
File "token_test.py", line 16, in test_build_drive
drive.close()
File "/Users/ghaithbilbeisi/miniconda3/lib/python3.8/site-packages/googleapiclient/discovery.py", line 1335, in close
self._http.http.close()
AttributeError: 'Http' object has no attribute 'http'
I'm going to close off this issue as google-auth-httplib2 0.1.0 was released on Monday with the fix from googleapis/google-auth-library-python-httplib2#14 . If you're still having trouble after updating google-auth-httplib2, please re-open this issue with more information.
Traceback (most recent call last):
File "test_code.py", line 4, in <module>
yt.close()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleapiclient/discovery.py", line 1364, in close
self._http.http.close()
AttributeError: 'Http' object has no attribute 'http'
Process finished with exit code 1
@busunkim96 actually #1231 did not fixed the issue since I am still having it:
Traceback (most recent call last):
File "./src/sheet2xls.py", line 20, in <module>
sheet = sheet_obj.get(sheet_id)
File "/home/runner/.local/lib/python3.8/site-packages/gsheets/api.py", line 141, in get
return self[id***
File "/home/runner/.local/lib/python3.8/site-packages/gsheets/api.py", line 121, in __getitem__
response = backend.spreadsheet(self._sheets, id)
File "/home/runner/.local/lib/python3.8/site-packages/gsheets/tools.py", line 39, in __get__
result = instance.__dict__[self.__name__*** = self.fget(instance)
File "/home/runner/.local/lib/python3.8/site-packages/gsheets/api.py", line 69, in _sheets
return backend.build_service('sheets', credentials=self._creds,
File "/home/runner/.local/lib/python3.8/site-packages/gsheets/backend.py", line 34, in build_service
return apiclient.discovery.build(**kwargs)
File "/home/runner/.local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/runner/.local/lib/python3.8/site-packages/googleapiclient/discovery.py", line 324, in build
discovery_http.close()
AttributeError: 'Http' object has no attribute 'close'
##[error***Process completed with exit code 1.
The stack trace seems to suggest it's failing on closing discovery_http, which is just a plain httplib2 object rather than one from google_auth_httplib2.
Could you try this code to see if you can close a plain httplib2.Http instance? If this doesn't work, the version of httplib2 you have installed may be too old.
Hi @niva83 , I'm going to close this off as guidance has been provided in #1046 (comment). If you're still having trouble, please re-open it with more information.
This bug should be reopened for Python 2 users as the fix has not yet been backported to a v1 release of the client library. Since I can't reopen this issue due to (lack of) perms, I filed this new bug as a proxy.
Activity
busunkim96 commentedon Sep 28, 2020
Hey @ghaithbilbeisi, could you show more of the stack trace?
From discussion in #1047 it looks like the issue is the low version of
httplib2. I also see that this wouldn't work correctly if you were passing in your ownhttplib2object (in that case it should just beself._http.close()).ghaithbilbeisi commentedon Sep 30, 2020
Hi @busunkim96 , I get this when running my unittest with the following:
Using the following authenticate and build_drive methods:
Running this with google-api-python-client 1.12.3, httplib2 0.18.1, and python 3.8.3 gives the following error:
busunkim96 commentedon Sep 30, 2020
I think the proper fix for this is to add
closeto AuthorizedHttp. Opened googleapis/google-auth-library-python-httplib2#14feat: add close method (#14)
parthea commentedon Mar 3, 2021
I'm going to close off this issue as google-auth-httplib2 0.1.0 was released on Monday with the fix from googleapis/google-auth-library-python-httplib2#14 . If you're still having trouble after updating google-auth-httplib2, please re-open this issue with more information.
solzard commentedon Mar 5, 2021
This simple code still raises the same error with latest packages (
google-auth-httplib2 0.1.0,httplib2 0.19.0,google-api-python-client 2.0.2).busunkim96 commentedon Mar 5, 2021
I think #1231 will (finally) fix this. I'll circle back to it next week. Thanks for the report @solzard!
fix: fix .close() (#1231)
nikokaoja commentedon Apr 7, 2021
@busunkim96 actually #1231 did not fixed the issue since I am still having it:
from
pip list:google-api-core 1.26.3
google-api-python-client 2.1.0
google-auth 1.28.0
google-auth-httplib2 0.1.0
googleapis-common-protos 1.53.0
httplib2 0.19.1
busunkim96 commentedon Apr 7, 2021
@niva83 I'm not able to reproduce the error you're seeing. Could you share the bit of your code that calls
discovery.build?The stack trace seems to suggest it's failing on closing
discovery_http, which is just a plainhttplib2object rather than one fromgoogle_auth_httplib2.google-api-python-client/googleapiclient/discovery.py
Line 324 in a5d2081
Could you try this code to see if you can close a plain
httplib2.Httpinstance? If this doesn't work, the version of httplib2 you have installed may be too old.nikokaoja commentedon Apr 7, 2021
@busunkim96 thanks, I will test this week and let you know how it goes.
parthea commentedon Apr 14, 2021
Hi @niva83 , I'm going to close this off as guidance has been provided in #1046 (comment). If you're still having trouble, please re-open it with more information.
wescpy commentedon May 31, 2025
This bug should be reopened for Python 2 users as the fix has not yet been backported to a v1 release of the client library. Since I can't reopen this issue due to (lack of) perms, I filed this new bug as a proxy.
feat: add close method (#14)