Selenium headless browser webdriver [Errno 104] Connection reset by peer
Asked Answered
H

3

11

I am trying to scrape data from the URLs below. But selenium fails when driver.get(url) Some times the error is [Errno 104] Connection reset by peer, sometimes [Errno 111] Connection refused. On rare days it works just fine and on my mac with real browser the same spider works fine every single time. So this isn't related to my spider.

Have tried many solutions like waiting got selectors on page, implicit wait, using selenium-requests yo pass proper request headers, etc. But nothing seems to work.

http://www.snapdeal.com/offers/deal-of-the-day
https://paytm.com/shop/g/paytm-home/exclusive-discount-deals

I am using python, selenium & headless Firefox webdriver to achieve this. The os is centos 6.5.

Note: I have many AJAX heavy pages that gets scraped successfully some are below.

http://www.infibeam.com/deal-of-the-day.html, http://www.amazon.in/gp/goldbox/ref=nav_topnav_deals

Already spent many days trying to debug the issue with no luck. Any help would be appreciated.

Hoopes answered 1/9, 2015 at 9:30 Comment(0)
H
17

After days of jingling around this issue, finally found the cause. Writing it here for the benefit of the community. The headless browser was failing due to lack of RAM on the server, strange error messages from webdriver were real pita.

The server was running straight up for 60 days without reboot, Rebooting it did the trick. After increasing the swap by 3 times, has not faced issue for past few days. Also scheduled a task to cleanup page file caches (http://www.yourownlinux.com/2013/10/how-to-free-up-release-unused-cached-memory-in-linux.html).

Hoopes answered 5/9, 2015 at 13:6 Comment(0)
T
7

I have been using Selenium and chromedriver (python3) for scraping purposes for some time now. With the latest Google Chrome update I had to deal with two issues.

1) Error on webdriver launch:

Solution: I had to add "no-sandbox" argument.

chrome_options.add_argument('--no-sandbox')

2) [Errno 104] Connection reset by peer:

Solution. There seems to be a problem with sockets and http requests. Either the webpage content is too big or you don't give the page enough time to load. At least that's what I thought. I set the maximum page load time to 60 seconds and it seems to be working fine.

driver.set_page_load_timeout(60)

I added a small delay between webdrivers initialisations which also seems to help.

time.sleep(0.5)

Terrorist answered 20/1, 2018 at 9:58 Comment(1)
did you mean "--no-sandbox"? or should it be without two preceding hyphens?Sneed
E
7

Found this question while looking for similar error. Look's like it's a selenium 3.8.1 and 3.9.0 bug.

https://github.com/SeleniumHQ/selenium/issues/5296

Downgrade to 3.8.0 solves this problem

Expeditionary answered 26/2, 2018 at 6:59 Comment(1)
Thank you! Looks like it's working once downgraded. Hope it will behave the same :)Sneed

© 2022 - 2024 — McMap. All rights reserved.