Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

httplib2.ServerNotFoundError: Unable to find the server at www.googleapis.com

When i try to fetch the details of gmail using google-api's (googleapiclient,oauth2client), i am getting below error:

 File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/google_api_python_client-1.7.8-py2.7.egg/googleapiclient/_helpers.py", line 130, in positional_wrapper

  File "/usr/local/lib/python2.7/site-packages/google_api_python_client-1.7.8-py2.7.egg/googleapiclient/discovery.py", line 224, in build

  File "/usr/local/lib/python2.7/site-packages/google_api_python_client-1.7.8-py2.7.egg/googleapiclient/discovery.py", line 274, in _retrieve_discovery_doc
  File "/usr/local/lib/python2.7/site-packages/httplib2-0.12.1-py2.7.egg/httplib2/__init__.py", line 2135, in request
    cachekey,
  File "/usr/local/lib/python2.7/site-packages/httplib2-0.12.1-py2.7.egg/httplib2/__init__.py", line 1796, in _request
    conn, request_uri, method, body, headers
  File "/usr/local/lib/python2.7/site-packages/httplib2-0.12.1-py2.7.egg/httplib2/__init__.py", line 1707, in _conn_request

    raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
httplib2.ServerNotFoundError: Unable to find the server at www.googleapis.com

but it is working fine in my pc but not from remote location.

code:

from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

credentials = ServiceAccountCredentials.from_json_keyfile_name(
            "quickstart-1551349397232-e8bcb3368ae1.json", scopes=
['https://www.googleapis.com/auth/admin.directory.group',                                                                  'https://www.googleapis.com/auth/admin.directory.user',                                                                  'https://www.googleapis.com/auth/admin.directory.domain',                                                                  'https://www.googleapis.com/auth/gmail.readonly'])

delegated_credentials = credentials.create_delegated('[email protected]')

DIRECOTORY = build('admin', 'directory_v1', credentials=delegated_credentials)

try:
    results = DIRECOTORY.users().list(customer='my_customer').execute()   
    users = results.get('users', [])    
    res = []    
    for info in users:         
    print(info)          
    res.append(info.get("primaryEmail"))
    print(res)
except Exception as e:
    print(e)

Any help would be much appreciated.

Thanks in advance.

like image 592
Kusalkumar Avatar asked Jan 25 '26 08:01

Kusalkumar


1 Answers

I had the same issue and I searched a lot to get it fixed, turns out I was at fault here.

I don't know from where there was podman installed instead of docker and that caused the problem.

I suggest you check your docker version and make sure the latest is running at the server, otherwise, the library works fine! Please let me know if you still face this issue, would like to dig deep!

like image 102
Aashish Chaubey Avatar answered Jan 27 '26 22:01

Aashish Chaubey