webbrowser

A

Antonio Ceballos

Hello,

I am trying to open a URL on a new browser or new tab from an HTML page
created from a python cgi script. On Apache in my localhost, it works, both
with Internet Explorer and Firefox. However, when I upload the script to a
remote server, it does not. A 500 Internal Server Error is displayed on the
browser.

The (simplified) piece of code is as follows:

import webbrowser
webbrowser.open_new(http://www.google.com)

The server runs python 2.3. I am using python 2.5 in my localhost.

Can anybody figure out why this may be happening?

Cheers,
Antonio
 
D

Dennis Lee Bieber

Hello,

I am trying to open a URL on a new browser or new tab from an HTML page
created from a python cgi script. On Apache in my localhost, it works, both
with Internet Explorer and Firefox. However, when I upload the script to a
remote server, it does not. A 500 Internal Server Error is displayed on the
browser.

The (simplified) piece of code is as follows:

import webbrowser
webbrowser.open_new(http://www.google.com)

The server runs python 2.3. I am using python 2.5 in my localhost.

Can anybody figure out why this may be happening?
Well... I don't know when the webbrowser module came into existance
-- it may not be in Python 2.3

HOWEVER, the most likely reason is that that code tries to open a
browser window on the machine that is executing the code. When testing
on "localhost", you have a full environment with display and browser.

After you put that program into the server CGI area, the code tries
to open a browser window ON THE SERVER. I suspect the server machine
doesn't even have an attached display device, and probably doesn't have
any browser software installed.

It will NOT open a new window on YOUR machine when accessed via the
remote server. For that you will probably need to write Javascript that
creates new window/tab... or whatever HTML (if any) directs a browser to
do such.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
C

Cameron Walsh

Antonio said:
Hello,

I am trying to open a URL on a new browser or new tab from an HTML page
created from a python cgi script.

import cgitb; cgitb.enable()
# Will save you hours of debugging. Prints error messages and
exceptions to the client, wrapped in pretty html.

On Apache in my localhost, it works, both
with Internet Explorer and Firefox. However, when I upload the script to a
remote server, it does not. A 500 Internal Server Error is displayed on the
browser.

Check your server logs - they give more information on the cause of the
error.
The (simplified) piece of code is as follows:

import webbrowser
webbrowser.open_new(http://www.google.com)

try: webbrowser.open_new("http://www.google.com") instead.

But the main problem is that you cannot make a web client open their
browser. What your code does is make whichever computer is running the
cgi code (i.e. the server) open a browser pointing to http://www.google.com.

It works on your home machine, because you have a graphical interface
running and python can open whatever browser it chooses. The code would
work if it wasn't a cgi file (or requested by a web browser and executed
by a python handler on the server in any way).


Why not make the cgi file print the javascript that would make the
client open another window?

The server runs python 2.3. I am using python 2.5 in my localhost.

The webbrowser module is present in python 2.3 but it is not what you
want. You might also have other unrelated problems in the code. Use
import cgitb; cgitb.enable() and check your server logs.


Hope that helps,

Cameron.
 
A

Antonio Ceballos

Dennis, Cameron,

You are absolutely right. I was not aware that the cgi was trying to open
the new browser on the server -I am a beginner with cgi, python and
javascript.

This simple javascript does the job perfectly:

window.open("http://www.google.com");

Thanks a lot,
Antonio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top