Selenium-Requests
Selenium-Requests copied to clipboard
RemoteDisconnected('Remote end closed connection without response')) on getting request header
OS: Alpine Linux 3.19.1
Python: 3.11.8
Selenium-Requests: 2.0.4
BrowserVersion: 123.0.6312.105
chromedriverVersion: 123.0.6312.105
Some findings:
- current_window_handle before switching back is the same as
original_window_handle - sleep 1 second before switching will not trigger the error
from selenium import webdriver
import seleniumrequests
def get_chrome_option():
option = webdriver.ChromeOptions()
option.add_argument('--no-sandbox')
option.add_argument('--headless')
option.add_argument('--disable-dev-shm-usage')
return option
driver = seleniumrequests.Chrome(get_chrome_option())
driver.get('https://www.google.com/')
driver.request('get', 'https://www.google.com/')
Traceback (most recent call last):
File "/root/streaming/lib/python3.11/site-packages/urllib3/connectionpool.py", line 793, in urlopen
response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/connectionpool.py", line 537, in _make_request
response = conn.getresponse()
^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/connection.py", line 466, in getresponse
httplib_response = super().getresponse()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/http/client.py", line 1390, in getresponse
response.begin()
File "/usr/lib/python3.11/http/client.py", line 325, in begin
version, status, reason = self._read_status()
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/http/client.py", line 294, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/streaming/lib/python3.11/site-packages/seleniumrequests/request.py", line 160, in request
self.requests_session.headers = get_webdriver_request_headers(self, proxy_host=self.__proxy_host)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/seleniumrequests/request.py", line 80, in get_webdriver_request_headers
webdriver.switch_to.window(original_window_handle)
File "/root/streaming/lib/python3.11/site-packages/selenium/webdriver/remote/switch_to.py", line 133, in window
self._w3c_window(window_name)
File "/root/streaming/lib/python3.11/site-packages/selenium/webdriver/remote/switch_to.py", line 141, in _w3c_window
send_handle(window_name)
File "/root/streaming/lib/python3.11/site-packages/selenium/webdriver/remote/switch_to.py", line 137, in send_handle
self._driver.execute(Command.SWITCH_TO_WINDOW, {"handle": h})
File "/root/streaming/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 345, in execute
response = self.command_executor.execute(driver_command, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/selenium/webdriver/remote/remote_connection.py", line 302, in execute
return self._request(command_info[0], url, body=data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/selenium/webdriver/remote/remote_connection.py", line 322, in _request
response = self._conn.request(method, url, body=body, headers=headers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/_request_methods.py", line 144, in request
return self.request_encode_body(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/_request_methods.py", line 279, in request_encode_body
return self.urlopen(method, url, **extra_kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/poolmanager.py", line 444, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/connectionpool.py", line 847, in urlopen
retries = retries.increment(
^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/util/retry.py", line 470, in increment
raise reraise(type(error), error, _stacktrace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/util/util.py", line 38, in reraise
raise value.with_traceback(tb)
File "/root/streaming/lib/python3.11/site-packages/urllib3/connectionpool.py", line 793, in urlopen
response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/connectionpool.py", line 537, in _make_request
response = conn.getresponse()
^^^^^^^^^^^^^^^^^^
File "/root/streaming/lib/python3.11/site-packages/urllib3/connection.py", line 466, in getresponse
httplib_response = super().getresponse()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/http/client.py", line 1390, in getresponse
response.begin()
File "/usr/lib/python3.11/http/client.py", line 325, in begin
version, status, reason = self._read_status()
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/http/client.py", line 294, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))