Navigation Menu

Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Selenium don't initialized if 127.0.0.1 have more then one alias in hosts file #3280

Closed
lukeis opened this issue Mar 3, 2016 · 32 comments
Closed

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 3280

What steps will reproduce the problem?
1. write more then one alias for 127.0.0.1, (ex. www.100myr.com) in hosts file in c:\windows\system32\drivers\etc\
2. try to initialize selenium driver (ex. driver = new FirefoxDriver();)

What is the expected output? What do you see instead?
I see next error
org.openqa.selenium.UnsupportedCommandException: Bad request

Command duration or timeout: 1.08 seconds
Build info: version: '2.17.0', revision: '15546', time: '2012-01-16 17:11:34'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version:
'1.7.0'
Driver info: driver.version: FirefoxDriver

Selenium version: 2.17.0
OS: Windows XP
Browser: Firefox 
Browser version: 9.0.1

If I have only one alias for 127.0.0.1 then I haven't error.

Reported by Sergewar on 2012-01-26 06:43:49

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by barancev on 2012-01-26 09:01:10

  • Labels added: Component-WebDriver

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Can you post your entire hosts file, please?

Reported by dawagner on 2012-01-26 18:25:47

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

File "hosts" in attach.

Reported by Sergewar on 2012-01-27 09:02:29


- _Attachment: [hosts_orig](https://storage.googleapis.com/google-code-attachments/selenium/issue-3280/comment-3/hosts_orig)_

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I was able to reproduce this error as well on CENTOS 5.  Which by default includes you
machines hostname in /etc/hosts as 127.0.0.1

With my hosts file like:

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost vmdev localhost.localdomain
::1             localhost6.localdomain6 localhost6


FirefoxDriver fails.

With my host file changed to:


# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost

127.0.0.2 vmdev localhost.localdomain

::1             localhost6.localdomain6 localhost6

The FirefoxDriver works fine.

This happens both using the driver directly, and through the RemoteDriverServer

Reported by crnelson on 2012-02-04 16:38:48

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I'm seeing exactly the same problem with Selenium 2.20.0 on CentOS 5.7. The workaround
described in the previous comment (Feb 4th 2012) fixed the problem. 

However, I've also noticed that it is possible to run the FirefoxDriver successfully
with more than one alias for 127.0.0.1 in /etc/hosts just so long as the localhost
alias is the first one mentioned. That is, with /etc/hosts looking like below, trying
to initialise the FirefoxDriver fails with the "org.openqa.selenium.UnsupportedCommandException:
Bad request" problem...

------------------------------/etc/hosts---------------------------
# Do not remove the following line, or various programs
# that require network functionality will fail.

127.0.0.1    myalias myotheralias localhost.localdomain localhost

::1          localhost6.localdomain6 localhost6

-------------------------------------------------------------------


But, if the order of the 127.0.0.1 aliases is changed to put localhost at the front
then the FirefoxDriver works fine...

------------------------------/etc/hosts---------------------------
# Do not remove the following line, or various programs
# that require network functionality will fail.

127.0.0.1    localhost localhost.localdomain myalias myotheralias

::1          localhost6.localdomain6 localhost6

-------------------------------------------------------------------

Hope this helps.



Reported by george.harley on 2012-03-15 13:00:18

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I too had same issue on my XP machine and when followed the comment# 4 fixed the issue.

Thanks,
Aditya

Reported by gentlemayhem on 2012-03-28 06:33:54

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

This issue may have been fixed in 2.21. Please report back if this now works better.

Reported by kristian.rosenvold on 2012-04-14 19:48:29

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I tried this with 2.21 and it is still an issue.  Changing the 127.0.0.1 entry fixes
it.

Reported by mattluce on 2012-05-16 14:05:49

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I saw some slightly different behavior.

I only had one 127.0.0.1 entry in my hosts file but the host associated with it was
localhost.mydomain.com.

Under this configuration Firefox would launch when executing my tests through maven
but would fail to launch with the above error when using the TestNG plugin in Eclipse.

I added another entry for 127.0.0.1 just 'localhost' and now Firefox launches in both
maven and eclipse.... weird.

Reported by youngm on 2012-05-22 01:28:51

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

This happens for us as well.

Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:08:56'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.18-308.13.1.el5',
java.version: '1.6.0_33'

My hosts file:

127.0.0.1       localhost.domain.com localhost

If I change it to...

127.0.0.1       localhost localhost.domain.com

...everything works fine.

Our companies servers hosts file is updated from central server every hour and it's
not possible to change that, so the fix is needed.

Reported by mikko.p.kallioniemi on 2012-10-16 07:02:20

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I'm able to reproduce the issue with Selenium 2.25.0 and a RHEL6 machine. The suggestion
above fixes the problem.

Reported by karel.piwko on 2012-10-24 06:35:38

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Issue does still exist in 2.29.1

Reported by patrick@ch.tario.org on 2013-02-15 13:58:08

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Hi All,

I am executing a very simple code. I am facing the same problem. I am using Windows
XP with Firefox 20.0.1 and Selenium-Java 2.32.0. I tried above fixes but did not work.
Could somebody please help me.

CODE:
import org.openqa.selenium.firefox.FirefoxDriver;


public class Gmail {


    public static void main(String[] args) {

        FirefoxDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");
    }

}

STACK TRACE:
Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Bad request

Command duration or timeout: 172 milliseconds
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version:
'1.7.0_21'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
    at Gmail.main(Gmail.java:9)


Reported by ramkumar.harish on 2013-05-01 05:41:25

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reproduced.

Reported by barancev on 2013-11-01 19:08:43

  • Status changed: Accepted

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Same bug on 2.37.0 on CentOS 6.4.
And same workaround.

Reported by Andrew.Golovkov on 2013-11-13 10:36:50

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I have the same problem and all I can say is many thanks to the inital poster for actually
pointing out what was causing the misbehavior.

Reported by camille.espanol on 2014-01-07 08:09:45

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Just one more user burned by this.  I found that if I more my additional alias after
the localhost, localhost.localdomain entries (so that it's at the end), then it works.

Reported by darrell.esau on 2014-08-20 17:56:21

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Issue 7711 has been merged into this issue.

Reported by barancev on 2014-08-27 14:22:57

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

This issue was closed by revision 1ada6dd7056c.

Reported by barancev on 2014-08-27 19:23:42

  • Status changed: Fixed

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

In order to allow connections from aliases other than "localhost" one have to start
FirefoxDriver with a tuned profile:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "alias1,alias2");
WebDriver driver = new FirefoxDriver(profile);

The fix will be released in version 2.43

Reported by barancev on 2014-08-27 19:31:07

  • Labels added: Browser-Firefox

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Thanks for fixing the issue.
What is the expected release date for 2.43?

Reported by satmce on 2014-09-02 07:07:58

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Thanks a lot.. i have followed #4 and it started working for me...

Reported by jagadeesh.tel on 2014-09-04 09:38:10

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Can you please let me know the right usage of this method.. 
For example, I have below content in host#1 & host#2 at /etc/hosts
How can I write a code to call this FirefoxProfile.ALLOWED_HOSTS_PREFERENCE with my
profile to make it work for both host?


#host1:
=======
127.0.0.1 localhost.localdomain loghost
10.229.244.186 abc1210310.us.oracle.com abc1210310
10.229.244.186 oidhost.us.oracle.com oidhost

#host2
======
127.0.0.1 localhost.localdomain localhost loghost
10.229.244.184 cde1210310.us.oracle.com cde1210310
10.229.244.184 oiahost.us.oracle.com oiahost

Reported by satmce on 2014-09-14 07:08:01

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Issue 4344 has been merged into this issue.

Reported by barancev on 2014-10-01 18:22:40

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

My hosts file is:
127.0.0.1 something.set.by.my.company

I tried the following code, but I still get the same problem. How should I change the
code?

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE,"localhost");
driver = new FirefoxDriver(profile);

Reported by vasile.pop on 2014-10-08 08:09:47

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE,"something.set.by.my.company");

Reported by barancev on 2014-10-08 08:23:45

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

That was so...obvious, stupid me. Thanks!

Reported by vasile.pop on 2014-10-08 08:42:05

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Thanks a lot! followed number 4 and fixed the issue.

Reported by abulhasanlakhani on 2014-11-10 00:14:50

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Problem: this is reproducible when using Selenium Grid. Unfortunately, there's no way
of using ALLOWED_HOSTS_PREFERENCE for RemoteWebDriver. Can we reopen this?

Reported by vasile.pop on 2015-07-09 14:28:30

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I too have the same problem

The line in my /etc/hosts is as follows 
127.0.0.1       localhost.localdomain   loghost localhost

Tried setting it like
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE,"localhost.localdomain,loghost,localhost");

But that does not work. 

Reported by albinjacob on 2015-09-15 05:32:01

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Also am using selenium-server-standalone-2.44.0.jar

Reported by albinjacob on 2015-09-15 05:33:12

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:14:39

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant