Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems Opening Firefox

I'm trying to write a Python script to open a URL, but I keep getting errors when I try to use it:

import webbrowser

firefox = webbrowser.get('mozilla')

This is the error:

Traceback (most recent call last):
  File "C:\Users\Gelu\Documents\CSCI\Image URL Generator\src\Generator.py", line 8, in <module>
    firefox = webbrowser.get('mozilla')
  File "C:\Program Files\Python31\lib\webbrowser.py", line 53, in get
    raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser

Any ideas why this isn't working?

like image 723
Ryan Avatar asked Dec 23 '10 09:12

Ryan


People also ask

Is there an issue with Firefox?

Mozilla.org is UP and reachable by us.


2 Answers

For me the issue was, webbrowser.py did not recognize any other browser in my windows machine. So, i had to register the browser and then launch a new tab.

import webbrowser
urL='https://www.google.com'
firefox_path="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"
webbrowser.register('firefox', None,webbrowser.BackgroundBrowser(firefox_path),1)
webbrowser.get('firefox').open_new_tab(urL)

Hope this helps some one.

Also some python notes for reference on what register does ,

webbrowser.register(name, constructor[, instance])¶

Register the browser type name. Once a browser type is registered, the get() function can return a controller for that browser type. If instance is not provided, or is None, constructor will be called without parameters to create an instance when needed. If instance is provided, constructor will never be called, and may be None.This entry point is only useful if you plan to either set the BROWSER variable or call get() with a nonempty argument matching the name of a handler you declare.

like image 164
Yogamurthy Avatar answered Sep 17 '22 20:09

Yogamurthy


if you do

import webbrowser
print webbrowser._browsers

you will get a list of the recognized browsers on your system.

like image 23
Hugh Bothwell Avatar answered Sep 19 '22 20:09

Hugh Bothwell