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

T

Terry Reedy

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

We need more volunteers who will do the kind of careful review of
report, doc, and code I just did. Feel free to help.
 
L

llanitedave

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).







so that Chrome does not return an error code, in which case IE should

*not* be tried as a backup.


Terry, after what I've learned today I'm tempted to agree that it's not necessarily a bug, and that maybe all that's needed is a bit more clarity in the documentation.

On the other hand, it *is* a bit frustrating that Linux recognizes an html-style relative path, while Windows insists on the entire absolute path. Maybe we can call it a Windows bug, but a workaround would be nice to have.

However, combined with os.path.abspath(), it's not a huge issue -- once we understand the approach.

I certainly appreciate your taking the time to make an analysis of it, and someday I hope to have the time and skills to help out in some small way.
 
L

llanitedave

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).







so that Chrome does not return an error code, in which case IE should

*not* be tried as a backup.


Terry, after what I've learned today I'm tempted to agree that it's not necessarily a bug, and that maybe all that's needed is a bit more clarity in the documentation.

On the other hand, it *is* a bit frustrating that Linux recognizes an html-style relative path, while Windows insists on the entire absolute path. Maybe we can call it a Windows bug, but a workaround would be nice to have.

However, combined with os.path.abspath(), it's not a huge issue -- once we understand the approach.

I certainly appreciate your taking the time to make an analysis of it, and someday I hope to have the time and skills to help out in some small way.
 
C

Chris Angelico

On the other hand, it *is* a bit frustrating that Linux recognizes an html-style relative path, while Windows insists on the entire absolute path. Maybe we can call it a Windows bug, but a workaround would be nice to have.

That is, unfortunately, an all-too-common platform difference. But I'd
say that you do have that workaround:
However, combined with os.path.abspath(), it's not a huge issue -- once we understand the approach.

If that works reliably on all platforms, I'd say that that's exactly
the nice-to-have that you describe.

ChrisA
 
T

Terry Reedy

On the other hand, it *is* a bit frustrating that Linux recognizes an
html-style relative path, while Windows insists on the entire
absolute path. Maybe we can call it a Windows bug, but a workaround
would be nice to have.

You can file an enhancement issue, preferably with a patch and test, as
I do not expect anyone else to write a patch.
 
M

Matej Cepl

url_link = "file:///" + fullpath

Isn't this too many slashes. On Linux I get URI

file:////usr/share/doc/whatever.html

which is just too many slashes (it should be three, two for the
protocol, one for the root directory).

Matěj
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top