Pygsheets unable to find the server at www.googleapis.com
Asked Answered
S

0

6

I'm trying to use pygsheets in a script on ScrapingHub. The pygsheets part of the script begins with:

google_client = pygsheets.authorize(service_file=CREDENTIALS_FILENAME, no_cache=True)
spreadsheet = google_client.open_by_key(SHEET_ID)

Where CREDENTIALS_FILENAME is my Google service account credentials file name and SHEET_ID is the spreadsheet ID; at some point of that, this is happening:

2018-01-30 16:27:36 INFO [stdout] service_email : *******@**********.iam.gserviceaccount.com
2018-01-30 16:27:36 INFO [googleapiclient.discovery] URL being requested: GET https://www.googleapis.com/drive/v3/files?corpora=user&pageSize=500&fields=files%28id%2C+name%29&q=mimeType%3D%27application%2Fvnd.google-apps.spreadsheet%27&supportsTeamDrives=false&includeTeamDriveItems=false&alt=json
2018-01-30 16:27:36 INFO [oauth2client.transport] Attempting refresh to obtain initial access_token
2018-01-30 16:27:36 INFO [oauth2client.client] Refreshing access_token
2018-01-30 16:31:50 ERROR [root] Job runtime exception
Traceback (most recent call last):
  File "/app/python/lib/python3.6/site-packages/httplib2/__init__.py", line 995, in _conn_request
    conn.connect()
  File "/usr/local/lib/python3.6/http/client.py", line 1392, in connect
    super().connect()
  File "/usr/local/lib/python3.6/http/client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/local/lib/python3.6/socket.py", line 704, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/local/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sh_scrapy/crawl.py", line 148, in _run_usercode
    _run(args, settings)
  File "/usr/local/lib/python3.6/site-packages/sh_scrapy/crawl.py", line 105, in _run
    _run_pkgscript(args)
  File "/usr/local/lib/python3.6/site-packages/sh_scrapy/crawl.py", line 128, in _run_pkgscript
    d.run_script(scriptname, {'__name__': '__main__'})
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1517, in run_script
    exec(code, namespace, namespace)
  File "/tmp/unpacked-eggs/__main__.egg/EGG-INFO/scripts/update_gsheets.py", line 190, in <module>
    main(parse_args())
  File "/tmp/unpacked-eggs/__main__.egg/EGG-INFO/scripts/update_gsheets.py", line 152, in main
    google_client = pygsheets.authorize(service_file=CREDENTIALS_FILENAME, no_cache=True)
  File "/app/python/lib/python3.6/site-packages/pygsheets/client.py", line 552, in authorize
    rclient = Client(oauth=credentials, **client_kwargs)
  File "/app/python/lib/python3.6/site-packages/pygsheets/client.py", line 79, in __init__
    self._fetch_sheets()
  File "/app/python/lib/python3.6/site-packages/pygsheets/client.py", line 92, in _fetch_sheets
    results = self._execute_request(None, request, False)
  File "/app/python/lib/python3.6/site-packages/pygsheets/client.py", line 418, in _execute_request
    response = request.execute()
  File "/app/python/lib/python3.6/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/app/python/lib/python3.6/site-packages/googleapiclient/http.py", line 839, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "/app/python/lib/python3.6/site-packages/googleapiclient/http.py", line 166, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/app/python/lib/python3.6/site-packages/oauth2client/transport.py", line 175, in new_request
    redirections, connection_type)
  File "/app/python/lib/python3.6/site-packages/oauth2client/transport.py", line 282, in request
    connection_type=connection_type)
  File "/app/python/lib/python3.6/site-packages/httplib2/__init__.py", line 1322, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/app/python/lib/python3.6/site-packages/httplib2/__init__.py", line 1072, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/app/python/lib/python3.6/site-packages/httplib2/__init__.py", line 1002, 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

I've tested the script before and it used to work, so I don't know what is happening. What is this happening? There is some configuration or authentication step that I missed?

Sprague answered 30/1, 2018 at 18:3 Comment(2)
did you verify if your internet is working ? try pinging www.googleapis.comPelias
@nithin Yes, it is working. The script works in my PC actually, but it doesn't remotely. I pinged www.googleapis.com and works.Sprague

© 2022 - 2024 — McMap. All rights reserved.