I'm posting here because im facing an error I have not been able to fix. I'm currently developing an application to make my work easier. It basically connects and automatically downloads and processes a report and then uploads it to google sheets. I finished the automated download section, which runs every 5 minutes, and was working fine. A couple of days have passed and I finished the rest of the program, and now that I have to glue it all together I cannot get to work the part that was previously downloading the reports fine, and weirdest of all, its throwing an error on the simplest of lines (a driver.get()). Here is an extract of the code:
options = webdriver.ChromeOptions()
if self.headless:
options.add_argument('headless')
options.add_argument('disable-gpu')
if self.imgless:
prefs = {'profile.managed_default_content_settings.images':2}
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(options=options, executable_path="C:\\Windows\\chromedriver.exe")
download_dir = tempfile.TemporaryDirectory().name
os.mkdir(download_dir)
driver.command_executor._commands["send_command"] = ("POST",'/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir,
"download.prompt_for_download": False}}
driver.execute("send_command", params)
driver.get('Site removed')
username = driver.find_element_by_id('username')
username.send_keys(self.username)
It opens the page fine, but then it throws an error on the driver.get() line. The complete error is as follows (sorry, really long).
Traceback (most recent call last):
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "C:\Program Files\Python37\lib\http\client.py", line 1321, in getresponse
response.begin()
File "C:\Program Files\Python37\lib\http\client.py", line 296, in begin
version, status, reason = self._read_status()
File "C:\Program Files\Python37\lib\http\client.py", line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Program Files\Python37\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/felip/PycharmProjects/ConexionesCL/venv/main.py", line 390, in <module>
CL = ConexionesCL(username, password, 'creds.json', headless=False)
File "C:/Users/felip/PycharmProjects/ConexionesCL/venv/main.py", line 37, in __init__
self.loop()
File "C:/Users/felip/PycharmProjects/ConexionesCL/venv/main.py", line 42, in loop
self.dir = self.getMR()
File "C:/Users/felip/PycharmProjects/ConexionesCL/venv/main.py", line 324, in getMR
driver.get('Site removed from post')
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\request.py", line 72, in request
**urlopen_kw)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\request.py", line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\poolmanager.py", line 323, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\util\retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
raise value
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 306, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='127.0.0.1', port=49927): Read timed out. (read timeout=<object object at 0x00000201FA69E2B0>)
I know huge blocks of text are bad in questions, but I want to include as much info as possible.
Really confused as to why it stopped working so suddenly. Using latest chromedriver and selenium.
Any help is greatly appreciated.
Edit://
So, I just managed to fix this by doing socket.setdefaulttimeout(None) in the function that checks for internet connectivity. Pretty dumb mistake.