0

I'm trying to use Google Sheets with Python. I went to their quickstart tutorial and have been trying to get it to run for quite some time behind a company proxy. I'm on Windows 7, and I've changed the HTTP_PROXY and HTTPS_PROXY environment variables appropriately and have also tried setting them in the command prompt prior to running the code. Code is below and error it spits out is below that:

from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools


SCOPES = 'https://www.googleapis.com/auth/spreadsheets'
CLIENT_SECRET = 'client_secret.json'
store = file.Storage('storage.json')
credz = store.get()
if not credz or credz.invalid:
    flow = client.flow_from_clientsecrets(CLIENT_SECRET, SCOPES)
    credz = tools.run_flow(flow, store) #ERROR ON THIS LINE

Error1:

File "C:\Users\myusername\AppData\Local\Programs\Python\Python35\lib\socket.py",

line 732, in getaddrinfo

for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11004] getaddrinfo failed

Then it spits out "During handling of the above exception, another exception occurred:"

File

"C:\Users\myusername\AppData\Local\Programs\Python\Python35\lib\site-packages\httplib2__init__.py",

line 994, in _conn_request

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

accounts.google.com

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Jcloud
  • 41
  • 3

1 Answers1

0

You may check this thread wherein the suggested workaround is to add custom attributes to your exception class, like:

class MyError(Exception):
    def __init__(self, message, cause):
        super(MyError, self).__init__(message + u', caused by ' + repr(cause))
        self.cause = cause

try:
    v = {}['a']
except KeyError as e:
    raise MyError('failed', e)

Sometimes, you might need to provide credentials to a proxy server in order to use it. Usually, they are submitted using a base64 hash included in an HTTP header.

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • I'm not entirely sure how the first part of your answer relates to my question; could you please explain? As for the second part, I believe that's what they used for a previous iteration of the Google API (1 or 2) and I believe the most recent is version 4. Regardless, there's no document detailing what to do I Python in regards to configuring the proxy for Google API that I could find. Thanks though! – Jcloud Jan 19 '17 at 16:50