Forums

can't access published Google Sheet in JSON format

Hi there,

I've placed some data in a Google Sheet. Then I File>Published it to the web. I'm now trying to read the data in JSON format using the URL

https://spreadsheets.google.com/feeds/list/1OUmpAgT8IgwNSa7OWh_YFAzCOXsvc5R9ZHlpqYdxdNo/default/public/values?alt=json

This URL works fine from my own computer. I get JSON and am able to further process it. But when I try it from pythonanywhere (web2py, using urllib.urlopen()), I don't get JSON. I get HTML which at some point says

The following error was encountered while trying to retrieve the URL: https://spreadsheets.google.com/feeds/list/1N2DmnSw4mJH8MPSsNOPM95-xmBkipV_Gx_hcqcQlSVc/default/public/values? Unsupported Request Method and Protocol Squid does not support all request methods for all access protocols. For example, you can not POST a Gopher request.

Can you suggest a solution to access the Google Sheet in JSON format? This is just a quick-and-dirty so I'd prefer not to have to go through an API like gspread if not needed.

Thank you for any suggestions! -Ricardo

A GET request on that URL works fine. Try

curl https://spreadsheets.google.com/feeds/list/1OUmpAgT8IgwNSa7OWh_YFAzCOXsvc5R9ZHlpqYdxdNo/default/public/values?alt=json

and you'll see that. Your code is probably not making a GET request or you're not making the proxy request correctly. See http://help.pythonanywhere.com/pages/403ForbiddenError/ - particularly the part title "Proxy Details"

Glenn, thanks for your response. You were right - I was using the urllib library, which does not automatically recognize your proxy settings. So I tested the urllib2 and requests libraries. Both urllib2.urlopen() and requests.get() work fine without adding proxies or changing the URL protocol.

Then I went back to test urllib.urlopen() with proxies. Adding your HTTP proxy.server:3128 worked, but also required changing the url protocol to HTTP.

This worked:

response = urllib.urlopen('http://...', proxies={'http': 'http://proxy.server:3128'})

But if I tried to open an HTTPS URL, I would get:

<type 'exceptions.IOError'> [Errno socket error] [Errno 1] _ssl.c:510: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

thanks again! -Ricardo

I believe that's because of a bug in urllib.