ConnectionResetError: [Errno 104] Connection reset by peer and ERR_NAME_NOT_RESOLVED on heroku with mobile testing through Selenium

前端 未结 2 1321
清酒与你
清酒与你 2020-12-11 04:03

I\'d like to test multiple mobile user agents with selenium and chrome. I\'m using python 3.6 and deploying to heroku. Based on http://chromedriver.chromium.org/mobile-emula

相关标签:
2条回答
  • 2020-12-11 04:43

    ConnectionResetError: [Errno 104] Connection reset by peer

    In general when a client terminates abruptly without closing the connection a RST packet is sent by the TCP/IP stack of the underlying OS. Python converts this into an exception with the text Connection reset by peer. As per your error stack trace it means that once self._read_status() was invoked (internally) Python assumed to receive something but the connection was suddenly dropped and Python informs you of this error by raising the exception:

    ConnectionResetError: [Errno 104] Connection reset by peer
    

    The situation is somewhat similar to this expression:

    "Connection reset by peer" is the TCP/IP equivalent of slamming the phone back on the hook. It's more polite than merely not replying, leaving one hanging. But it's not the FIN-ACK expected of the truly polite TCP/IP converseur.

    There can be multiple probabilities behind this error as follows.


    Solution Stage A

    A quick and a precise solution will be to add a few recommended ChromeOptions along with the existing one as follows:

    options.add_argument("start-maximized"); // open Browser in maximized mode
    options.add_argument("disable-infobars"); // disabling infobars
    options.add_argument("--disable-extensions"); // disabling extensions
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage"); // overcome limited resource problems
    

    and then

    return webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, options=options) 
    

    Note: You need to remove the argument options.add_argument('--disable-gpu') as it is applicable to windows OS only.


    Solution Stage B

    A couple of points:

    • As per the documentation within Python Chrome Mobile Emulation the Key and Value pair seems to be "deviceName": "Google Nexus 5" (not "deviceName": "Nexus 5")
    • You can tweak you code to invoke Remote() through either of the following ways-

      • Invoking Remote() through DesiredCapabilities():

        from selenium import webdriver
        # import DesiredCapabilities was missing in your program
        from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
        
        mobile_emulation = { "deviceName": "Google Nexus 5" }
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
        capabilities = DesiredCapabilities.CHROME
        capabilities = options.to_capabilities()
        driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities = capabilities)
        
      • You find a similar discussion on invoking Remote() through ChromeOptions() in How to add selenium chrome options to 'desiredCapabilities'?

      • Invoking Remote() through ChromeOptions():

        from selenium import webdriver
        mobile_emulation = { "deviceName": "Google Nexus 5" }
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
        driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', options=chrome_options)
        
      • You find a similar discussion on invoking Remote() through ChromeOptions() in Remote WebDriver UnreachableBrowserException: Could not start a new session

    • For your reference here is the link to the documentation on Webdriver.android
    • For your reference here is the link to the documentation on Getting started with Selendroid

    Solution Stage C

    If you are still seeing the error, perform the following upgradation/cleanup tasks:

    • Upgrade Selenium to current levels Version 3.13.0.
    • Upgrade ChromeDriver to current ChromeDriver v2.40 level.
    • Keep Chrome version between Chrome v66-68 levels. (as per ChromeDriver v2.40 release notes)
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • (WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
    • (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
    • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
    • Take a System Reboot.
    • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
    • Execute your @Test.

    Solution Stage D

    Looking out for a granular solution to specific error I stepped into Amazon S3 and "Connection Reset by Peer" where Garry Dolley summerizes the the cause of the problem to be a combination of the below mentioned factors:

    • TCP Window Scaling
    • Linux kernels 2.6.17 or newer

    Linux kernels 2.6.17+ increased the maximum size of the TCP window/buffer, and this started to cause other gear to wig out, if it couldn’t handle sufficiently large TCP windows. The gear would reset the connection, and we see this as a “Connection reset by peer” message.

    A pottential solution will be to put the following entries within /etc/sysctl.conf:

    • net.ipv4.tcp_wmem = 4096 16384 512000
    • net.ipv4.tcp_rmem = 4096 87380 512000

    Note: This fix is easy peasy, but it’ll slow your maximum throughput inexchange of faster downloads.


    PS

    If applicable, ensure that /etc/hosts on your system contains the following entry :

    127.0.0.1               localhost.localdomain localhost
    

    Related Discussions

    Here are some of the related discussions:

    • Python socket.error: [Errno 104] Connection reset by peer
    • Yet Another 'Connection reset by peer' Error
    • Connection reset by peer [errno 104] in Python 2.7
    • Remote WebDriver UnreachableBrowserException: Could not start a new session
    • How to add selenium chrome options to 'desiredCapabilities'?

    References

    Here are the references of this discussion:

    • Example Python Chrome Mobile Emulation Automated Unit Testing Using Selenium 2 WebDriver ChromeDriver
    • Amazon S3 and "Connection Reset by Peer"
    • How To: Network / TCP / UDP Tuning
    • How To : Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint
    • Mobile Emulation
    • selenium.webdriver.android.webdriver
    • Getting started with Selendroid
    0 讨论(0)
  • 2020-12-11 04:51

    The specific error message says

    android's server IP address could not be found.

    To me, that indicates that the browser is trying to lookup a DNS entry for android, which isn't a valid TLD. By chance, is the browser attempting to access http://android, rather than something like https://www.google.com? I can replicate that same error message in my own Chrome by typing http://android into the address bar. This leads me to believe that specifying a proper url for the browser should resolve the issue.

    0 讨论(0)
提交回复
热议问题