Python webbrowser - Check if browser is available (nothing happens when opening webpage over an SSH connection)
<p>Is there a way to detect whether there is a browser available on the system on which the script is run? Nothing happens when running the following code on a server:</p>

<pre><code>try:
    webbrowser.open("file://" + os.path.realpath(path))
except webbrowser.Error:
    print "Something went wrong when opening webbrowser"
</code></pre>

<p>It's weird that there's no caught exception, and no open browser. I'm running the script from command line over an SSH-connection, and I'm not very proficient in server-related stuff, so there may be another way of detecting this that I am missing.</p>

<p>Thanks!</p>

<p>Checkout the <a href="https://docs.python.org/2/library/webbrowser.html" rel="nofollow">documentation</a>:</p>

<blockquote>
  <p>webbrowser.<strong>get</strong>([name])</p>
  
  <p>Return a controller object for the browser type name. If name is empty, return a controller for a default browser appropriate to the callerâs environment.</p>
</blockquote>

<p>This works for me:</p>

<pre><code>try:
    # we are not really interested in the return value
    webbrowser.get()
    webbrowser.open("file://" + os.path.realpath(path))
except Exception as e:
    print "Webbrowser error: " % e
</code></pre>

<p>Output:</p>

<pre><code>Webbrowser error: could not locate runnable browser
</code></pre>

python python-webbrowser