Using pythons webbrowser.open in snaped applications

Ok, will try with xdg-open for now then. Thanks!

Using xdg-open results in a permission denied error.

  File "main.py", line 337, in __quitApplication
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

very important: make sure to not have xdg-open inside the snap (do not put it into stage-packages or build-packages)…

@sergiusens What do you think about blacklisting certain packages from stage-packages? Certainly xdg-open would be a candidate.

1 Like

We already do that per base, so if you build on 16.04 LTS there’s a list of dependencies we do not follow unless explicitly stated.

Per base? Can you elaborate please.

Sorry, I got it mixed up with another feature, this is the list https://github.com/snapcore/snapcraft/blob/master/snapcraft/internal/repo/manifest.txt

I just checked, xdg-open is not in the resulting snap. Also I have not put it in the yaml file anywhere explicitly. So that should be fine.
Anything else that I can check?

What is the permission denied about? What is it trying to run and being unable to?

It should definitely be able to execute xdg-open.

I’m not sure what the permission is about. All I do at that time is
subprocess.Popen(["xdg-open", self.website])
where website is a simple website URL either to my website or to an irc channel.

Just an idea:
“xdg-open”, self.website [as is]
“xdg-open_”, self.website [transform, do not use]
"xdg-open ", self.website [solution!?]


EDIT: Added the: [explanations]

1 Like

I’ve tried with the underscore and the space at the end, both end up in a file not found error e.g.

FileNotFoundError: [Errno 2] No such file or directory: 'xdg-open_'

not sure what’s the difference in your first version though.

Sorry, the underscore was only to “show” the gap.

I don’t know your surrounding, it was only an idea that you might call
xdg-openhttp://xyz.ab instead of xdg-open http://xyz.ab.


With Java you could make it in this way:
Runtime.getRuntime().exec("xdg-open " + infoUrlString);

Sorry, I forgot there were recent changes around this. Access to xdg-open was just recently opened up as you can see in this conversation.

As an easy workaround, you can try copying the trivial xdg-open script in your snap for the time being, until this change goes live in an upcoming core snap. The script is just a shell line sending a message over DBus.

Please let us know how it goes, and I’m sorry for the trouble there.

1 Like

UPDATE: On i386 it is in “stable” now.
stable: 16-2.27.6 (2901) 81MB
candidate: 16-2.27.6 (2901) 81MB

are you sure?

channels:                                    
  stable:    16-2.27.6                (2898) 85MB -
  candidate: 16-2.27.6                (2898) 85MB -
1 Like

note the revisions differ between architectures … just looking at the numbers wont help :wink:

channels:                                    
  stable:    16-2.27.6                (2900) 72MB -
  candidate: 16-2.27.6                (2900) 72MB -

(on armhf :wink: )

2 Likes

Yes, I am. … aaamhhhhhhh …was sure. :grin: Maybe I should add “on i386”. Many thanks!

2 Likes

Okay. Thanks for that.
But what about the “xdg-open regression”?
What # is it in which architecture, or was it in i386 only?

Thanks for your help and all the information, adding the unity7 plug to my app made xdg-open work properly.

2 Likes