I'm pretty new to this and it's taken me days to get this far, the script I have now that pushes a JSON feed into a Google Sheet works for my test link, but times out when used with the URL I actually need to pull from.
I can confirm the real URL works, and I have access - I'm able to print to terminal no problem.
It has sensitive info, so I'm unable to share - I've looked into proxies, and URIs, but haven't really been able how to figure any of it out with my code.
# import urllib library
import json
from urllib.request import urlopen, Request
import gspread
import requests
gc = gspread.service_account(filename='creds.json')
sh = gc.open_by_key('1-1aiGMn2yUWRlh_jnIebcMNs-6phzUNxkktAFH7uY9o')
worksheet = sh.sheet1
url = 'URL LINK GOES HERE'
# store the response of URL
response = urlopen(Request(url, headers={"User-Agent": ""}))
r = requests.get("URL LINK GOES HERE",
proxies={"http": "http://61.233.25.166:80"})
# storing the JSON response
# from url in data
data_json = json.loads(response.read())
# print the json response
# print(data_json)
result = []
for key in data_json:
result.append([key, data_json[key] if not isinstance(
data_json[key], list) else ",".join(map(str, data_json[key]))])
worksheet.update('a1', result)
# proxies///uris///url 100% works
Does anyone have advice on how I could avoid the timeout? Full error is below:
Traceback (most recent call last):
File "c:\Users\AMadle\NBA-JSON-Fetch\2PrintToSheetTimeoutTesting.py", line 17, in <module>
response = urlopen(Request(url, headers={"User-Agent": ""}))
File "C:\Python\python3.10.5\lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "C:\Python\python3.10.5\lib\urllib\request.py", line 519, in open
response = self._open(req, data)
File "C:\Python\python3.10.5\lib\urllib\request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "C:\Python\python3.10.5\lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
File "C:\Python\python3.10.5\lib\urllib\request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "C:\Python\python3.10.5\lib\urllib\request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>
from How to fix timeout while parsing a JSON feed into a Google Sheet?
No comments:
Post a Comment