0

We try to read the content of a Google Sheet from a Linux server behind a corporate proxy. Generally we are able to connect to the Internet through the proxy, e.g. pip install or python requests work fine. But the following does not:

export GOOGLE_APPLICATION_CREDENTIALS="path to our credentials file"
python
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
SAMPLE_SPREADSHEET_ID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
SAMPLE_RANGE_NAME = 'Sheet1!A1:J17'
service = build('sheets', 'v4')
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID, range=SAMPLE_RANGE_NAME).execute()

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 851, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 184, in _retry_request
    raise exception
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 165, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/google_auth_httplib2.py", line 187, in request
    self._request, method, uri, request_headers)
  File "/usr/local/lib/python3.6/site-packages/google/auth/credentials.py", line 122, in before_request
    self.refresh(request)
  File "/usr/local/lib/python3.6/site-packages/google/oauth2/service_account.py", line 322, in refresh
    request, self._token_uri, assertion)
  File "/usr/local/lib/python3.6/site-packages/google/oauth2/_client.py", line 145, in jwt_grant
    response_data = _token_endpoint_request(request, token_uri, body)
  File "/usr/local/lib/python3.6/site-packages/google/oauth2/_client.py", line 106, in _token_endpoint_request
    method='POST', url=token_uri, headers=headers, body=body)
  File "/usr/local/lib/python3.6/site-packages/google_auth_httplib2.py", line 116, in __call__
    url, method=method, body=body, headers=headers, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1957, in request
    cachekey,
  File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1622, in _request
    conn, request_uri, method, body, headers
  File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1528, in _conn_request
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1311, in connect
    self.sock = self._context.wrap_socket(sock, server_hostname=self.host)
  File "/usr/local/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/usr/local/lib/python3.6/ssl.py", line 817, in __init__
    self.do_handshake()
  File "/usr/local/lib/python3.6/ssl.py", line 1077, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/local/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)

How can we solve this issue?

Things we already checked:

user1091141
  • 581
  • 7
  • 19
  • Is the system clock correct? – Rafa Guillermo Oct 09 '19 at 13:47
  • I think yes: "Wed Oct 9 16:32:04 UTC 2019" at the time of this comment looks good. How can we strictly verify it is correct. – user1091141 Oct 09 '19 at 16:34
  • It does appear that this is correct, also make sure that the proxy server's system clock is also correct. There are many reasons that an SSL Certificate Verification can fail so I'm just trying to eliminate the simpler possibilities before delving deeper. – Rafa Guillermo Oct 10 '19 at 08:53
  • Not sure how to check the Proxy Server clock, but it should be correct, since I can call the URL with curl without error, e.g. ```curl -X POST https://oauth2.googleapis.com/token``` – user1091141 Oct 11 '19 at 10:50
  • Check out [this answer here](https://stackoverflow.com/questions/51077804/ssl-issue-while-installing-any-package-using-pip-behind-the-proxy/51078072#51078072) and make sure the proxy server is set up to accept SSL certificates. This has a very wide scope of issues it could be and debugging without client and server information is I can only really speculate what the issues may be. I think in this case it would be best to talk to the administrators of the corporate proxy. – Rafa Guillermo Oct 11 '19 at 11:30

0 Answers0