FAQ
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

Search Discussions

  • Cameron Walsh at Nov 14, 2007 at 6:45 am

    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.
  • Antonio Ceballos at Nov 15, 2007 at 12:48 am
    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" <aceballos at gmail.com> escribi? en el mensaje
    news:fhdhl4$ag0$1 at 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 14, '07 at 1:05a
activeNov 15, '07 at 12:48a
posts3
users2
websitepython.org

2 users in discussion

Antonio Ceballos: 2 posts Cameron Walsh: 1 post

People

Translate

site design / logo © 2022 Grokbase