Using gspread with proxy
Asked Answered
C

2

7

I am trying to access google spreadsheets through gspread api in python. I have imported gspread. I am getting socket. error: [Errno 10061] No connection could be made because the target machine actively refused it at gc = gspread.login('pan*******@gmail.com', '********')

Here is my code:

import urllib2
import urllib
import gspread
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

w = 420

gc = gspread.login('pan******@gmail.com', '*******')
wks = gc.open("Spreadsheet").sheet1

I have checked that the username and password is correct. I have added two environment variables as 'http_proxy':'host:port' and 'https_proxy':'host:port' What am I doing wrong? Thank you.

Cuss answered 9/4, 2015 at 21:51 Comment(1)
I ran into the same problem, since I am also working behind corporate proxy the gspread module didn't work for me and I got the same error as mentioned in the problem statement. I found one workaround i.e. use script editor in spreadsheet to write functions do things and you can call these function by send just http post request to the sheet.Adinaadine
C
2

For anyone who might have this problem, I found out that gspread library doesn't support proxy connections. I ran it through normal connection and it worked.

Cuss answered 29/9, 2015 at 9:20 Comment(0)
R
0

You can configure httplib to work throw proxy. For example for spreadsheet:

http = httplib2.Http(
    proxy_info=httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL,
                                  proxy_host, proxy_port,
                                  proxy_user=proxy_user, proxy_pass=proxy_pass))

httpAuth = credentials.authorize(http)  
service = apiclient.discovery.build('sheets', 'v4', http=httpAuth)  # using
Recurved answered 13/11, 2023 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.