Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > webbrowser.open("./documentation/help.html")-- No Go in Windows

Reply
Thread Tools

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

 
 
llanitedave
Guest
Posts: n/a
 
      02-24-2013
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" <(E-Mail Removed)> 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".
 
Reply With Quote
 
 
 
 
llanitedave
Guest
Posts: n/a
 
      02-24-2013
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" <(E-Mail Removed)> 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".
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      02-24-2013
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.
 
Reply With Quote
 
Demian Brecht
Guest
Posts: n/a
 
      02-24-2013
For the record, I completely misread and misunderstood the question. I
should stop posting that late at night

On Sun, Feb 24, 2013 at 1:25 AM, Demian Brecht <(E-Mail Removed)> 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 <(E-Mail Removed)> 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
 
Reply With Quote
 
llanitedave
Guest
Posts: n/a
 
      02-25-2013
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.
 
Reply With Quote
 
llanitedave
Guest
Posts: n/a
 
      02-25-2013
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.
 
Reply With Quote
 
llanitedave
Guest
Posts: n/a
 
      02-25-2013
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
>
>
>
> On Sun, Feb 24, 2013 at 1:25 AM, Demian Brecht <(E-Mail Removed)> 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 <(E-Mail Removed)> 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!
 
Reply With Quote
 
llanitedave
Guest
Posts: n/a
 
      02-25-2013
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
>
>
>
> On Sun, Feb 24, 2013 at 1:25 AM, Demian Brecht <(E-Mail Removed)> 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 <(E-Mail Removed)> 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!
 
Reply With Quote
 
llanitedave
Guest
Posts: n/a
 
      02-25-2013
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!
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      02-25-2013
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
!Windows Live Mail replace Outlook Express on Windows XP and Windows Mail on Vista... Max Burke NZ Computing 8 05-18-2007 12:10 AM
Windows XP Home Connected to Windows XP Pro via TCP/IP Armstrong Wong Wireless Networking 1 11-25-2004 01:12 PM
wireless ad-hoc with Windows XP and Windows 2000 =?Utf-8?B?ZHVtbWthdWY=?= Wireless Networking 1 09-23-2004 11:34 AM
Windows XP laptop and Windows 2000 desktop won't communicate =?Utf-8?B?UmlmbGVtYW4=?= Wireless Networking 0 08-19-2004 03:35 AM



Advertisments