By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

webbrowser

P: n/a
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
Nov 14 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Antonio Ceballos wrote:
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.
Nov 14 '07 #2

P: n/a
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
"Antonio Ceballos" <ac*******@gmail.comescribió en el mensaje
news:fh**********@hefestos.uned.es...
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


Nov 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.