webbrowser.open("./documentation/help.html")-- No Go in Windows

Discussion in 'Python' started by llanitedave, Feb 24, 2013.

  1. llanitedave

    llanitedave Guest

    I created an html help page for my Python 2.7.3 application and put it in adocumentation folder. I used webbrowser.open() to fetch the page.

    On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the weband does a Google search, returning nothing but useless noise.

    My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    How do I get a local html file to open properly from Python in Windows?
    llanitedave, Feb 24, 2013
    #1
    1. Advertising

  2. llanitedave

    Chris Rebert Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:
    >
    > I created an html help page for my Python 2.7.3 application and put it in

    a documentation folder. I used webbrowser.open() to fetch the page.
    >
    > On linux -- KDE specifically, the command opens the local file on my

    default browser with no issues. However, on Windows 7, it opens Internet
    Explorer, which doesn't even search the local folder, but goes straight to
    the web and does a Google search, returning nothing but useless noise.
    >
    > My default browser on Windows is Chrome, so my intention is getting

    undermined right from the start.
    >
    > How do I get a local html file to open properly from Python in Windows?


    Please provide the exact code snippet that you're using.

    Cheers,
    Chris
    Chris Rebert, Feb 24, 2013
    #2
    1. Advertising

  3. Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    Rather than using a relative path, try using
    webbrowser.open('{}/documentation/help.html'.format(os.path.dirname(__file__))).

    On Sun, Feb 24, 2013 at 1:17 AM, llanitedave <> wrote:
    > I created an html help page for my Python 2.7.3 application and put it ina documentation folder. I used webbrowser.open() to fetch the page.
    >
    > On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.
    >
    > My default browser on Windows is Chrome, so my intention is getting undermined right from the start.
    >
    > How do I get a local html file to open properly from Python in Windows?
    > --
    > http://mail.python.org/mailman/listinfo/python-list




    --
    Demian Brecht
    http://demianbrecht.github.com
    Demian Brecht, Feb 24, 2013
    #3
  4. llanitedave

    Chris Rebert Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:
    >
    > I created an html help page for my Python 2.7.3 application and put it in

    a documentation folder. I used webbrowser.open() to fetch the page.
    >
    > On linux -- KDE specifically, the command opens the local file on my

    default browser with no issues. However, on Windows 7, it opens Internet
    Explorer, which doesn't even search the local folder, but goes straight to
    the web and does a Google search, returning nothing but useless noise.
    >
    > My default browser on Windows is Chrome, so my intention is getting

    undermined right from the start.
    >
    > How do I get a local html file to open properly from Python in Windows?


    Sounds like this might be your problem:
    http://bugs.python.org/issue8936

    The fix would seem to be ensuring that the URL you pass includes the scheme
    (in your case, "file:").

    Cheers,
    Chris
    Chris Rebert, Feb 24, 2013
    #4
  5. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:
    > On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:
    >
    > >

    >
    > > I created an html help page for my Python 2.7.3 application and put it in a documentation folder.  I used webbrowser.open() to fetch the page.

    >
    > >

    >
    > > On linux -- KDE specifically, the command opens the local file on my default browser with no issues.  However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >
    >
    > >

    >
    > > My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >
    > >

    >
    > > How do I get a local html file to open properly from Python in Windows?

    >
    > Sounds like this might be your problem:
    >
    > http://bugs.python.org/issue8936
    >
    > The fix would seem to be ensuring that the URL you pass includes the scheme (in your case, "file:").
    >
    > Cheers,
    >
    > Chris


    Holy Toledo! That's a two-year-old bug spanning two versions of the language!

    BTW, Chris, the snippet I showed in the title essentially WAS the exact code. It's a method with that single line called from a wxPython Help menu. I can't really put an absolute pathname into the argument, because the application is going to be distributed to a variety of computers at my workplace, and there's no assurance that it will go into (or remain in)a particularfolder.

    I was trying to avoid using the wx.html.HtmlWindow feature of wxPython, because it doesn't handle CSS and styles. My help page is the portal to a multi-page users guide with a style sheet to render all the content consistently.

    Plus, I couldn't get the wx.html.HtmlWindow to open relative paths either -- it gave me "URL Malformed" messages even in KDE, when webbrowser.open("filepath") was working for the exact same path. But that's something to takeup on the wxPython list, I guess.

    This to me illustrates the downside of the Python philosophy of "There should be only one obvious way to do things". If that one obvious way has a fatal bug, you're pretty much SOL.
    llanitedave, Feb 24, 2013
    #5
  6. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:
    > On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:
    >
    > >

    >
    > > I created an html help page for my Python 2.7.3 application and put it in a documentation folder.  I used webbrowser.open() to fetch the page.

    >
    > >

    >
    > > On linux -- KDE specifically, the command opens the local file on my default browser with no issues.  However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >
    >
    > >

    >
    > > My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >
    > >

    >
    > > How do I get a local html file to open properly from Python in Windows?

    >
    > Sounds like this might be your problem:
    >
    > http://bugs.python.org/issue8936
    >
    > The fix would seem to be ensuring that the URL you pass includes the scheme (in your case, "file:").
    >
    > Cheers,
    >
    > Chris


    Holy Toledo! That's a two-year-old bug spanning two versions of the language!

    BTW, Chris, the snippet I showed in the title essentially WAS the exact code. It's a method with that single line called from a wxPython Help menu. I can't really put an absolute pathname into the argument, because the application is going to be distributed to a variety of computers at my workplace, and there's no assurance that it will go into (or remain in)a particularfolder.

    I was trying to avoid using the wx.html.HtmlWindow feature of wxPython, because it doesn't handle CSS and styles. My help page is the portal to a multi-page users guide with a style sheet to render all the content consistently.

    Plus, I couldn't get the wx.html.HtmlWindow to open relative paths either -- it gave me "URL Malformed" messages even in KDE, when webbrowser.open("filepath") was working for the exact same path. But that's something to takeup on the wxPython list, I guess.

    This to me illustrates the downside of the Python philosophy of "There should be only one obvious way to do things". If that one obvious way has a fatal bug, you're pretty much SOL.
    llanitedave, Feb 24, 2013
    #6
  7. llanitedave

    Chris Rebert Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sun, Feb 24, 2013 at 12:28 PM, llanitedave <> wrote:
    > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:
    >> On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:
    >> > I created an html help page for my Python 2.7.3 application and put itin a documentation folder. I used webbrowser.open() to fetch the page.
    >> > On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.
    >> > My default browser on Windows is Chrome, so my intention is getting undermined right from the start.
    >> > How do I get a local html file to open properly from Python in Windows?

    >>
    >> Sounds like this might be your problem:
    >> http://bugs.python.org/issue8936
    >>
    >> The fix would seem to be ensuring that the URL you pass includes the scheme (in your case, "file:").

    >
    > Holy Toledo! That's a two-year-old bug spanning two versions of the language!
    >
    > BTW, Chris, the snippet I showed in the title essentially WAS the exact code.


    Sorry, my bad. This is why I dislike messages that put critical info
    *only* in the subject line; I tend not to reread the subject line once
    I've opened the message.

    > It's a method with that single line called from a wxPython Help menu. Ican't really put an absolute pathname into the argument, because the application is going to be distributed to a variety of computers at my workplace, and there's no assurance that it will go into (or remain in)a particular folder.


    As Demian demonstrated, you can simply compute the absolute path from
    the relative path at runtime; although I would probably toss an
    abspath() call in for good measure
    (http://docs.python.org/2/library/os.path.html#os.path.abspath ).

    > This to me illustrates the downside of the Python philosophy of "There should be only one obvious way to do things". If that one obvious way has a fatal bug, you're pretty much SOL.


    On the other hand, you don't have to investigate which of N APIs is
    the "fixed"/"correct" one (Which PHP MySQL function is safe from SQL
    injection again?), and you only have wait for 1 fix instead of N. But
    yes, some of Python's included batteries are due for some recharging.

    Cheers,
    Chris
    Chris Rebert, Feb 24, 2013
    #7
  8. Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On 24/02/2013 20:28, llanitedave wrote:
    > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:
    >> On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:
    >>
    >>>

    >>
    >>> I created an html help page for my Python 2.7.3 application and put it in a documentation folder. I used webbrowser.open() to fetch the page.

    >>
    >>>

    >>
    >>> On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >>
    >>
    >>>

    >>
    >>> My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >>
    >>>

    >>
    >>> How do I get a local html file to open properly from Python in Windows?

    >>
    >> Sounds like this might be your problem:
    >>
    >> http://bugs.python.org/issue8936
    >>
    >> The fix would seem to be ensuring that the URL you pass includes the scheme (in your case, "file:").
    >>
    >> Cheers,
    >>
    >> Chris

    >
    > Holy Toledo! That's a two-year-old bug spanning two versions of the language!


    Only two years is nothing. Pay your money, take your choice :)

    > This to me illustrates the downside of the Python philosophy of "There should be only one obvious way to do things". If that one obvious way has a fatal bug, you're pretty much SOL.


    Misquoted as always. I guess that some day someone will quote it correctly.

    --
    Cheers.

    Mark Lawrence
    Mark Lawrence, Feb 24, 2013
    #8
  9. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 12:48:40 PM UTC-8, Chris Rebert wrote:
    > On Sun, Feb 24, 2013 at 12:28 PM, llanitedave <> wrote:
    >
    > > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:

    >
    > >> On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:

    >
    > >> > I created an html help page for my Python 2.7.3 application and put it in a documentation folder. I used webbrowser.open() to fetch the page.

    >
    > >> > On linux -- KDE specifically, the command opens the local file on mydefault browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >
    > >> > My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >
    > >> > How do I get a local html file to open properly from Python in Windows?

    >
    > >>

    >
    > >> Sounds like this might be your problem:

    >
    > >> http://bugs.python.org/issue8936

    >
    > >>

    >
    > >> The fix would seem to be ensuring that the URL you pass includes the scheme (in your case, "file:").

    >
    > >

    >
    > > Holy Toledo! That's a two-year-old bug spanning two versions of the language!

    >
    > >

    >
    > > BTW, Chris, the snippet I showed in the title essentially WAS the exactcode.

    >
    >
    >
    > Sorry, my bad. This is why I dislike messages that put critical info
    >
    > *only* in the subject line; I tend not to reread the subject line once
    >
    > I've opened the message.
    >


    Nah, my bad. I didn't realize that the title was the only place I'd put the actual command. I don't like it when other people do that either.

    >
    >
    > > It's a method with that single line called from a wxPython Help menu. I can't really put an absolute pathname into the argument, because the application is going to be distributed to a variety of computers at my workplace, and there's no assurance that it will go into (or remain in)a particular folder.

    >
    >
    >
    > As Demian demonstrated, you can simply compute the absolute path from
    >
    > the relative path at runtime; although I would probably toss an
    >
    > abspath() call in for good measure
    >
    > (http://docs.python.org/2/library/os.path.html#os.path.abspath ).
    >
    >


    OK, I'm going to have to study that one a bit. It looks like a new conceptfor my feeble brain.

    >
    > > This to me illustrates the downside of the Python philosophy of "There should be only one obvious way to do things". If that one obvious way has a fatal bug, you're pretty much SOL.

    >
    >
    >
    > On the other hand, you don't have to investigate which of N APIs is
    >
    > the "fixed"/"correct" one (Which PHP MySQL function is safe from SQL
    >
    > injection again?), and you only have wait for 1 fix instead of N. But
    >
    > yes, some of Python's included batteries are due for some recharging.
    >
    >
    >
    > Cheers,
    >
    > Chris


    You're right. It's one thing to have a persistent bug, it's another thing to offer the function in the documentation as if the bug doesn't exist.

    The bug report from October 2010 indicated that someone was working on a fix at that time. The fact that it's still not fixed implies that it might be something that's really hard to pin down. In a case like that, it's probably better to simply withdraw the feature, or tag it as "Non-windows only"
    llanitedave, Feb 24, 2013
    #9
  10. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 12:48:40 PM UTC-8, Chris Rebert wrote:
    > On Sun, Feb 24, 2013 at 12:28 PM, llanitedave <> wrote:
    >
    > > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:

    >
    > >> On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:

    >
    > >> > I created an html help page for my Python 2.7.3 application and put it in a documentation folder. I used webbrowser.open() to fetch the page.

    >
    > >> > On linux -- KDE specifically, the command opens the local file on mydefault browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >
    > >> > My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >
    > >> > How do I get a local html file to open properly from Python in Windows?

    >
    > >>

    >
    > >> Sounds like this might be your problem:

    >
    > >> http://bugs.python.org/issue8936

    >
    > >>

    >
    > >> The fix would seem to be ensuring that the URL you pass includes the scheme (in your case, "file:").

    >
    > >

    >
    > > Holy Toledo! That's a two-year-old bug spanning two versions of the language!

    >
    > >

    >
    > > BTW, Chris, the snippet I showed in the title essentially WAS the exactcode.

    >
    >
    >
    > Sorry, my bad. This is why I dislike messages that put critical info
    >
    > *only* in the subject line; I tend not to reread the subject line once
    >
    > I've opened the message.
    >


    Nah, my bad. I didn't realize that the title was the only place I'd put the actual command. I don't like it when other people do that either.

    >
    >
    > > It's a method with that single line called from a wxPython Help menu. I can't really put an absolute pathname into the argument, because the application is going to be distributed to a variety of computers at my workplace, and there's no assurance that it will go into (or remain in)a particular folder.

    >
    >
    >
    > As Demian demonstrated, you can simply compute the absolute path from
    >
    > the relative path at runtime; although I would probably toss an
    >
    > abspath() call in for good measure
    >
    > (http://docs.python.org/2/library/os.path.html#os.path.abspath ).
    >
    >


    OK, I'm going to have to study that one a bit. It looks like a new conceptfor my feeble brain.

    >
    > > This to me illustrates the downside of the Python philosophy of "There should be only one obvious way to do things". If that one obvious way has a fatal bug, you're pretty much SOL.

    >
    >
    >
    > On the other hand, you don't have to investigate which of N APIs is
    >
    > the "fixed"/"correct" one (Which PHP MySQL function is safe from SQL
    >
    > injection again?), and you only have wait for 1 fix instead of N. But
    >
    > yes, some of Python's included batteries are due for some recharging.
    >
    >
    >
    > Cheers,
    >
    > Chris


    You're right. It's one thing to have a persistent bug, it's another thing to offer the function in the documentation as if the bug doesn't exist.

    The bug report from October 2010 indicated that someone was working on a fix at that time. The fact that it's still not fixed implies that it might be something that's really hard to pin down. In a case like that, it's probably better to simply withdraw the feature, or tag it as "Non-windows only"
    llanitedave, Feb 24, 2013
    #10
  11. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 12:50:02 PM UTC-8, Mark Lawrence wrote:
    > On 24/02/2013 20:28, llanitedave wrote:
    >
    > > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:

    >
    > >> On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> I created an html help page for my Python 2.7.3 application and put it in a documentation folder. I used webbrowser.open() to fetch the page.

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >
    > >>

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> How do I get a local html file to open properly from Python in Windows?

    >
    > >>

    >
    > >> Sounds like this might be your problem:

    >
    > >>

    >
    > >> http://bugs.python.org/issue8936

    >
    > >>

    >
    > >> The fix would seem to be ensuring that the URL you pass includes the scheme (in your case, "file:").

    >
    > >>

    >
    > >> Cheers,

    >
    > >>

    >
    > >> Chris

    >
    > >

    >
    > > Holy Toledo! That's a two-year-old bug spanning two versions of the language!

    >
    >
    >
    > Only two years is nothing. Pay your money, take your choice :)
    >
    >
    >
    > > This to me illustrates the downside of the Python philosophy of "There should be only one obvious way to do things". If that one obvious way has a fatal bug, you're pretty much SOL.

    >
    >
    >
    > Misquoted as always. I guess that some day someone will quote it correctly.
    >
    >
    >
    > --
    >
    > Cheers.
    >
    >
    >
    > Mark Lawrence


    I think the correct quote is "You pays your money, and you takes your chances". ;)
    llanitedave, Feb 24, 2013
    #11
  12. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 12:50:02 PM UTC-8, Mark Lawrence wrote:
    > On 24/02/2013 20:28, llanitedave wrote:
    >
    > > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:

    >
    > >> On Feb 24, 2013 1:21 AM, "llanitedave" <> wrote:

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> I created an html help page for my Python 2.7.3 application and put it in a documentation folder. I used webbrowser.open() to fetch the page.

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >
    > >>

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> How do I get a local html file to open properly from Python in Windows?

    >
    > >>

    >
    > >> Sounds like this might be your problem:

    >
    > >>

    >
    > >> http://bugs.python.org/issue8936

    >
    > >>

    >
    > >> The fix would seem to be ensuring that the URL you pass includes the scheme (in your case, "file:").

    >
    > >>

    >
    > >> Cheers,

    >
    > >>

    >
    > >> Chris

    >
    > >

    >
    > > Holy Toledo! That's a two-year-old bug spanning two versions of the language!

    >
    >
    >
    > Only two years is nothing. Pay your money, take your choice :)
    >
    >
    >
    > > This to me illustrates the downside of the Python philosophy of "There should be only one obvious way to do things". If that one obvious way has a fatal bug, you're pretty much SOL.

    >
    >
    >
    > Misquoted as always. I guess that some day someone will quote it correctly.
    >
    >
    >
    > --
    >
    > Cheers.
    >
    >
    >
    > Mark Lawrence


    I think the correct quote is "You pays your money, and you takes your chances". ;)
    llanitedave, Feb 24, 2013
    #12
  13. llanitedave

    MRAB Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On 2013-02-24 20:28, llanitedave wrote:
    > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:

    [snip]
    >> Sounds like this might be your problem:
    >>
    >> http://bugs.python.org/issue8936
    >>
    >> The fix would seem to be ensuring that the URL you pass includes
    >> the scheme (in your case, "file:").
    >>

    > Holy Toledo! That's a two-year-old bug spanning two versions of the
    > language!
    >
    > BTW, Chris, the snippet I showed in the title essentially WAS the
    > exact code. It's a method with that single line called from a
    > wxPython Help menu. I can't really put an absolute pathname into the
    > argument, because the application is going to be distributed to a
    > variety of computers at my workplace, and there's no assurance that
    > it will go into (or remain in)a particular folder.
    >
    > I was trying to avoid using the wx.html.HtmlWindow feature of
    > wxPython, because it doesn't handle CSS and styles. My help page is
    > the portal to a multi-page users guide with a style sheet to render
    > all the content consistently.
    >
    > Plus, I couldn't get the wx.html.HtmlWindow to open relative paths
    > either -- it gave me "URL Malformed" messages even in KDE, when
    > webbrowser.open("filepath") was working for the exact same path. But
    > that's something to take up on the wxPython list, I guess.
    >
    > This to me illustrates the downside of the Python philosophy of
    > "There should be only one obvious way to do things". If that one
    > obvious way has a fatal bug, you're pretty much SOL.
    >

    I've had a brief look at webbrowser.py. It's looking for the browsers in
    the paths listed in the PATH environment variable.

    On my PC at least, the paths to the other browsers, such as "C:\Program
    Files\Mozilla Firefox" for Firefox, aren't listed there, hence the only
    one it can find is Internet Explorer.
    MRAB, Feb 24, 2013
    #13
  14. Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    For the record, I completely misread and misunderstood the question. I
    should stop posting that late at night :p

    On Sun, Feb 24, 2013 at 1:25 AM, Demian Brecht <> wrote:
    > Rather than using a relative path, try using
    > webbrowser.open('{}/documentation/help.html'.format(os.path.dirname(__file__))).
    >
    > On Sun, Feb 24, 2013 at 1:17 AM, llanitedave <> wrote:
    >> I created an html help page for my Python 2.7.3 application and put it in a documentation folder. I used webbrowser.open() to fetch the page.
    >>
    >> On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.
    >>
    >> My default browser on Windows is Chrome, so my intention is getting undermined right from the start.
    >>
    >> How do I get a local html file to open properly from Python in Windows?
    >> --
    >> http://mail.python.org/mailman/listinfo/python-list

    >
    >
    >
    > --
    > Demian Brecht
    > http://demianbrecht.github.com




    --
    Demian Brecht
    http://demianbrecht.github.com
    Demian Brecht, Feb 24, 2013
    #14
  15. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 2:15:10 PM UTC-8, MRAB wrote:
    > On 2013-02-24 20:28, llanitedave wrote:
    >
    > > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:

    >
    > [snip]
    >
    > >> Sounds like this might be your problem:

    >
    > >>

    >
    > >> http://bugs.python.org/issue8936

    >
    > >>

    >
    > >> The fix would seem to be ensuring that the URL you pass includes

    >
    > >> the scheme (in your case, "file:").

    >
    > >>

    >
    > > Holy Toledo! That's a two-year-old bug spanning two versions of the

    >
    > > language!

    >
    > >

    >
    > > BTW, Chris, the snippet I showed in the title essentially WAS the

    >
    > > exact code. It's a method with that single line called from a

    >
    > > wxPython Help menu. I can't really put an absolute pathname into the

    >
    > > argument, because the application is going to be distributed to a

    >
    > > variety of computers at my workplace, and there's no assurance that

    >
    > > it will go into (or remain in)a particular folder.

    >
    > >

    >
    > > I was trying to avoid using the wx.html.HtmlWindow feature of

    >
    > > wxPython, because it doesn't handle CSS and styles. My help page is

    >
    > > the portal to a multi-page users guide with a style sheet to render

    >
    > > all the content consistently.

    >
    > >

    >
    > > Plus, I couldn't get the wx.html.HtmlWindow to open relative paths

    >
    > > either -- it gave me "URL Malformed" messages even in KDE, when

    >
    > > webbrowser.open("filepath") was working for the exact same path. But

    >
    > > that's something to take up on the wxPython list, I guess.

    >
    > >

    >
    > > This to me illustrates the downside of the Python philosophy of

    >
    > > "There should be only one obvious way to do things". If that one

    >
    > > obvious way has a fatal bug, you're pretty much SOL.

    >
    > >

    >
    > I've had a brief look at webbrowser.py. It's looking for the browsers in
    >
    > the paths listed in the PATH environment variable.
    >
    >
    >
    > On my PC at least, the paths to the other browsers, such as "C:\Program
    >
    > Files\Mozilla Firefox" for Firefox, aren't listed there, hence the only
    >
    > one it can find is Internet Explorer.


    Well, it's still very odd, because when I use wxPython's wx.html.HtmlWindowto click a web link, it DOES use the default browser, which is Chrome on my PC. It's just using the webbrowser.open() function that goes to IE. Until then, I'd been suspecting that wx.html.HtmlWindow was using webbrowser.open() under the hood. I guess not.

    But wx.html.HtmlWindow doesn't work on relative paths, it seems (in neitherLinux NOR Windows), so I'm not able to find a substitute as of yet.
    llanitedave, Feb 25, 2013
    #15
  16. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 2:15:10 PM UTC-8, MRAB wrote:
    > On 2013-02-24 20:28, llanitedave wrote:
    >
    > > On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:

    >
    > [snip]
    >
    > >> Sounds like this might be your problem:

    >
    > >>

    >
    > >> http://bugs.python.org/issue8936

    >
    > >>

    >
    > >> The fix would seem to be ensuring that the URL you pass includes

    >
    > >> the scheme (in your case, "file:").

    >
    > >>

    >
    > > Holy Toledo! That's a two-year-old bug spanning two versions of the

    >
    > > language!

    >
    > >

    >
    > > BTW, Chris, the snippet I showed in the title essentially WAS the

    >
    > > exact code. It's a method with that single line called from a

    >
    > > wxPython Help menu. I can't really put an absolute pathname into the

    >
    > > argument, because the application is going to be distributed to a

    >
    > > variety of computers at my workplace, and there's no assurance that

    >
    > > it will go into (or remain in)a particular folder.

    >
    > >

    >
    > > I was trying to avoid using the wx.html.HtmlWindow feature of

    >
    > > wxPython, because it doesn't handle CSS and styles. My help page is

    >
    > > the portal to a multi-page users guide with a style sheet to render

    >
    > > all the content consistently.

    >
    > >

    >
    > > Plus, I couldn't get the wx.html.HtmlWindow to open relative paths

    >
    > > either -- it gave me "URL Malformed" messages even in KDE, when

    >
    > > webbrowser.open("filepath") was working for the exact same path. But

    >
    > > that's something to take up on the wxPython list, I guess.

    >
    > >

    >
    > > This to me illustrates the downside of the Python philosophy of

    >
    > > "There should be only one obvious way to do things". If that one

    >
    > > obvious way has a fatal bug, you're pretty much SOL.

    >
    > >

    >
    > I've had a brief look at webbrowser.py. It's looking for the browsers in
    >
    > the paths listed in the PATH environment variable.
    >
    >
    >
    > On my PC at least, the paths to the other browsers, such as "C:\Program
    >
    > Files\Mozilla Firefox" for Firefox, aren't listed there, hence the only
    >
    > one it can find is Internet Explorer.


    Well, it's still very odd, because when I use wxPython's wx.html.HtmlWindowto click a web link, it DOES use the default browser, which is Chrome on my PC. It's just using the webbrowser.open() function that goes to IE. Until then, I'd been suspecting that wx.html.HtmlWindow was using webbrowser.open() under the hood. I guess not.

    But wx.html.HtmlWindow doesn't work on relative paths, it seems (in neitherLinux NOR Windows), so I'm not able to find a substitute as of yet.
    llanitedave, Feb 25, 2013
    #16
  17. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 3:51:09 PM UTC-8, Demian Brecht wrote:
    > For the record, I completely misread and misunderstood the question. I
    >
    > should stop posting that late at night :p
    >
    >
    >
    > On Sun, Feb 24, 2013 at 1:25 AM, Demian Brecht <> wrote:
    >
    > > Rather than using a relative path, try using

    >
    > > webbrowser.open('{}/documentation/help.html'.format(os.path.dirname(__file__))).

    >
    > >

    >
    > > On Sun, Feb 24, 2013 at 1:17 AM, llanitedave <> wrote:

    >
    > >> I created an html help page for my Python 2.7.3 application and put itin a documentation folder. I used webbrowser.open() to fetch the page.

    >
    > >>

    >
    > >> On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >
    > >>

    >
    > >> My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >
    > >>

    >
    > >> How do I get a local html file to open properly from Python in Windows?

    >
    > >> --

    >
    > >> http://mail.python.org/mailman/listinfo/python-list

    >
    > >

    >
    > >

    >
    > >

    >
    > > --

    >
    > > Demian Brecht

    >
    > > http://demianbrecht.github.com

    >
    >
    >
    >
    >
    >
    >
    > --
    >
    > Demian Brecht
    >
    > http://demianbrecht.github.com


    Well, between you and Chris, I think you've got me on the right track. If things keep going like they are now, I should have it back under control inan hour or two.

    So, thanks in advance for all of you!
    llanitedave, Feb 25, 2013
    #17
  18. llanitedave

    llanitedave Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On Sunday, February 24, 2013 3:51:09 PM UTC-8, Demian Brecht wrote:
    > For the record, I completely misread and misunderstood the question. I
    >
    > should stop posting that late at night :p
    >
    >
    >
    > On Sun, Feb 24, 2013 at 1:25 AM, Demian Brecht <> wrote:
    >
    > > Rather than using a relative path, try using

    >
    > > webbrowser.open('{}/documentation/help.html'.format(os.path.dirname(__file__))).

    >
    > >

    >
    > > On Sun, Feb 24, 2013 at 1:17 AM, llanitedave <> wrote:

    >
    > >> I created an html help page for my Python 2.7.3 application and put itin a documentation folder. I used webbrowser.open() to fetch the page.

    >
    > >>

    >
    > >> On linux -- KDE specifically, the command opens the local file on my default browser with no issues. However, on Windows 7, it opens Internet Explorer, which doesn't even search the local folder, but goes straight to the web and does a Google search, returning nothing but useless noise.

    >
    > >>

    >
    > >> My default browser on Windows is Chrome, so my intention is getting undermined right from the start.

    >
    > >>

    >
    > >> How do I get a local html file to open properly from Python in Windows?

    >
    > >> --

    >
    > >> http://mail.python.org/mailman/listinfo/python-list

    >
    > >

    >
    > >

    >
    > >

    >
    > > --

    >
    > > Demian Brecht

    >
    > > http://demianbrecht.github.com

    >
    >
    >
    >
    >
    >
    >
    > --
    >
    > Demian Brecht
    >
    > http://demianbrecht.github.com


    Well, between you and Chris, I think you've got me on the right track. If things keep going like they are now, I should have it back under control inan hour or two.

    So, thanks in advance for all of you!
    llanitedave, Feb 25, 2013
    #18
  19. llanitedave

    llanitedave Guest

    Well, we can mark this one as solved.

    Simple enough, actually -- thanks to Chris and Demian for leading me to water.

    The following code works on both Linux and Windows 7:

    def OnDocs(self, event):
    """Opens the User's Guide in the default web browser"""
    fullpath = os.path.abspath('documentation/HTMLDocs/index.html')
    url_link = "file:///" + fullpath
    webbrowser.open(url_link)

    This allows both platforms to have their own idiosyncratic path structures without having to create separate code for each. It even chooses the correct browser!

    I learned some more about Python today, too. I'd never explored the 'os.' library before, and now I see things a little more clearly.

    Thanks again, guys!
    llanitedave, Feb 25, 2013
    #19
  20. llanitedave

    Terry Reedy Guest

    Re: webbrowser.open("./documentation/help.html")-- No Go in Windows

    On 2/24/2013 4:35 AM, Chris Rebert wrote:

    > Sounds like this might be your problem:
    > http://bugs.python.org/issue8936


    I just closed that issue an invalid. Here is most of what I wrote.
    '''
    After reading the doc and the code, I am convinced that current behavior
    is close to the implied wanted behavior, and that it is not a bug.

    The doc says
    webbrowser.open(url, new=0, autoraise=True)
    Display url using the default browser.

    What does 'default browswer' mean? Near the top, the doc says "If the
    environment variable BROWSER exists, it is interpreted to override the
    platform default list of browsers,". So the 'default browser' is
    actually the 'default browser list'. What open() does is to try each in
    turn and stop when one says it succeeded. So the doc should say 'using
    the first default browser that claims to succeed.'

    What does 'default browser list' mean? It depends on the platform *and*
    the software loaded on the particular machine when webbrowser is first
    imported in a particular instance of the interpreter. The 'platform'
    part is in the quote above, the rest is not. I will open a separate doc
    issue.

    On Windows, the list starts with 'default Windows browser', which calls
    os.startfile(), which, I believe, does call the user default browser.
    Next is Internet Explorer -- if available at that time on the particular
    machine! If the user-default browser rejects the url, then IE is tried.

    On my win7 machine today, I have Firefox the default and IE available.
    Firefox rejects 127.0.0.1:8080 with an 'Unable to connect' error box. IE
    'accepts' it in the sense that it displays an information starting 'The
    webpage cannot be displayed'.
    '''

    For *this* issue, I strongly suspect that Chrome is rejecting the
    invalid URL and telling Python so. So IE is tried next (but not first).

    > The fix would seem to be ensuring that the URL you pass includes the
    > scheme (in your case, "file:").


    so that Chrome does not return an error code, in which case IE should
    *not* be tried as a backup.

    --
    Terry Jan Reedy
    Terry Reedy, Feb 25, 2013
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. robin
    Replies:
    0
    Views:
    379
    robin
    May 18, 2006
  2. Thomas

    webbrowser open failing

    Thomas, Jul 26, 2006, in forum: Python
    Replies:
    0
    Views:
    275
    Thomas
    Jul 26, 2006
  3. Thomas

    Re: webbrowser open failing

    Thomas, Jul 26, 2006, in forum: Python
    Replies:
    0
    Views:
    392
    Thomas
    Jul 26, 2006
  4. Timur Tabi
    Replies:
    4
    Views:
    2,732
    Timur Tabi
    Jan 18, 2010
  5. Mitchell L Model
    Replies:
    1
    Views:
    477
    Paul Boddie
    Jan 27, 2010
Loading...

Share This Page