1

I am trying to open this local IP in my web browser.

   from selenium import webdriver
    driver = webdriver.Firefox()
    url = 'http://165.269.261.210/source/'
    page = urllib.urlopen(url)

when I run the above code it asks for username and password on Python shell.

Enter username for coffee at 165.269.261.210: agrawal

Warning (from warnings module):
  File "C:\Python27\Lib\getpass.py", line 92
    return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
Enter password for agrawal.a in coffee at 165.269.261.210: bravokid

after I provide username and password nothing opens in Firefox ? and also how can I provide username and password in the code itself ? Is there any better way to do it?

Update: When I directly put the link in the browser a pop-up opens asking for username and password. Only after I provide the username & password page opens otherwise throws 401 error

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
Ankit
  • 394
  • 1
  • 4
  • 16

1 Answers1

1

What you are doing here:

from selenium import webdriver
driver = webdriver.Firefox()
url = 'http://165.269.261.210/source/'

# This is no way connected to Selenium, but fetches URL using Python urllib library
# page = urllib.urlopen(url)
driver.get('http://username:password@165.269.261.210/source/')

Instead, use driver.get() method as explained in the Selenium WebDriver tutorial.

Further, you need to pass username and password in the URL for HTTP Basic Auth.

Community
  • 1
  • 1
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • Yes I think this is the right way. but in my case it is giving error IOError: [Errno http error] no host given – Ankit Apr 27 '15 at 08:48