1

I have to upload large file (more than 1GB size) using remote selenium server but get urllib.error.URLError <urlopen error [Errno 32] Broken pipe> error.

Here is a python code including remote driver setup which looks like:

from selenium.webdriver import ChromeOptions, Remote

options = ChromeOptions()
options.add_argument("--start-maximized")
remote = Remote(command_executor="http://localhost:9515",
                desired_capabilities=options.to_capabilities())
remote.find_element_by_css_selector('input[name="file"]'
                ).send_keys('path/to/file.iso'))

Here is a traceback sample error I have:

ERROR:   File "/home/user/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 475, in send_keys
ERROR:     value = self._upload(local_file)
ERROR:   File "/home/user/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 692, in _upload
ERROR:     return self._execute(Command.UPLOAD_FILE, {'file': content})['value']
ERROR:   File "/home/user/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute
ERROR:     return self._parent.execute(command, params)
ERROR:   File "/home/user/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
ERROR:     response = self.command_executor.execute(driver_command, params)
ERROR:   File "/home/user/.local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 472, in execute
ERROR:     resp = opener.open(request, timeout=self._timeout)
ERROR:   File "/usr/lib/python3.6/urllib/request.py", line 526, in open
ERROR:     response = self._open(req, data)
ERROR:   File "/usr/lib/python3.6/urllib/request.py", line 544, in _open
ERROR:     '_open', req)
ERROR:   File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
ERROR:     result = func(*args)
ERROR:   File "/usr/lib/python3.6/urllib/request.py", line 1346, in http_open
ERROR:     return self.do_open(http.client.HTTPConnection, req)
ERROR:   File "/usr/lib/python3.6/urllib/request.py", line 1320, in do_open
ERROR:     raise URLError(err)
ERROR: urllib.error.URLError: <urlopen error [Errno 32] Broken pipe>

Please note that files below 70mb size are uploading successfully but when I try to upload larger files it fails.

I use python 3.6, selenium 3.12.0, chromedriver 2.42 and Chrome 71. I did try with different selenium, chromedriver and Chrome versions but got the same error.

I suspect that there are some chromeoptions that I can use to fix this, but haven't found yet what exactly can help me.

I would appreciate your help!

1 Answer 1

1

If you use Remote WebDriver, it tries to transfer a file to be uploaded to a remote host (in your case from localhost to localhost; however, general logic is from a host where tests are running to a host where a browser is running).

As you upload a large file, a socket on the peer side is closed before the whole file is uploaded. That's why you see urllib.error.URLError: <urlopen error [Errno 32] Broken pipe>.

Solution: you need to disable file transfer by specifying UselessFileDetector

remote = Remote(
    command_executor="http://localhost:9515",
    desired_capabilities=options.to_capabilities(),
    file_detector=UselessFileDetector()
)

Please note that if your browser is located not at localhost, you have to care about transferring a file before uploading it with Selenium.

Edit: you can read more about how does Selenium upload files on https://extsoft.pro/selenium-large-files-upload/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.