The test tool Selenium 2.38.2 encountered a Bug in PhantomJS 1.9.2.

Source: Internet
Author: User
Tags readline connection reset

This Bug has been fixed in Selenium 2.38.4 released over the past two days. If Selenium of 2.38.1 and 2.38.2 is used, it will still be encountered. This Bug, before determining the cause, tortured me for a day or two; so I should record it.

Description: in the python 2.7 environment, when Selenium 2.38.2 and PhantomJS 1.9.2 are used to write a simple script to open a webpage, a Bug occurs and the webpage cannot be opened at all. The returned error message is "httplib. BadStatusLine:" "or" socket. error: [Errno 54] Connection reset by peer ". PS: I found that in the Python 2.6 environment, the same Selenium 2.38.2 and PhantomJS 1.9.2 usually do not encounter this problem (this problem has not been further investigated ).

For a detailed description and discussion, see this issue on the Selenium project home page: http://code.google.com/p/selenium/issues/detail? Id = 6690
Code specific Fix this bug in: https://github.com/SeleniumHQ/selenium/commit/a1df581908b7a0165dd232151647a23b5d6b4800

Solution: (very simple)

1. Roll back Selenium to 2.37.2;

The code is as follows: Copy code
Sudo pip uninstall selenium
Sudo pip install selenium = 2.37.2


2. Upgrade Selenium to 2.38.4.

The code is as follows: Copy code

Sudo pip install-U selenium


Possible error messages are as follows:

The code is as follows: Copy code
Jay @ jay-linux :~ /Workspace/python_test $ python try_phantomjs.py
Traceback (most recent call last ):
File "try_phantomjs.py", line 17, in <module>
Driver. get ("http://www.ip.cn/125.95.26.81 ")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver. py", line 176, in get
Self.exe cute (Command. GET, {'URL': url })
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver. py", line 162, in execute
Response = self.command_executor.exe cute (driver_command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 350, in execute
Return self. _ request (url, method = command_info [0], data = data)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 382, in _ request
Resp = self. _ conn. getresponse ()
File "/usr/lib/python2.7/httplib. py", line 1030, in getresponse
Response. begin ()
File "/usr/lib/python2.7/httplib. py", line 407, in begin
Version, status, reason = self. _ read_status ()
File "/usr/lib/python2.7/httplib. py", line 371, in _ read_status
Raise BadStatusLine (line)
Httplib. BadStatusLine :''


Occasionally, the following error message is returned:

The code is as follows: Copy code
Jay @ Jay-Air :~ /Workspace/python_study/dp/qa/2013/12 $ python try_phantomjs.py
Traceback (most recent call last ):
File "try_phantomjs.py", line 17, in <module>
Driver. get ("http://dianping.com /")
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver. py", line 176, in get
Self.exe cute (Command. GET, {'URL': url })
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver. py", line 162, in execute
Response = self.command_executor.exe cute (driver_command, params)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 355, in execute
Return self. _ request (url, method = command_info [0], data = data)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 384, in _ request
Resp = self. _ conn. getresponse ()
File "/System/Library/Frameworks/Python. framework/Versions/2.7/lib/python2.7/httplib. py", line 1045, in getresponse
Response. begin ()
File "/System/Library/Frameworks/Python. framework/Versions/2.7/lib/python2.7/httplib. py", line 409, in begin
Version, status, reason = self. _ read_status ()
File "/System/Library/Frameworks/Python. framework/Versions/2.7/lib/python2.7/httplib. py", line 365, in _ read_status
Line = self. fp. readline (_ MAXLINE + 1)
File "/System/Library/Frameworks/Python. framework/Versions/2.7/lib/python2.7/socket. py", line 476, in readline
Data = self. _ sock. recv (self. _ rbufsize)
Socket. error: [Errno 54] Connection reset by peer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.