Open a URL in Epiphany from Python Script on RPi2

360 Views Asked by At

So I am trying to open a URL in Epiphany WebBrowser [ let's say for example http://www.google.com ] from a python script. My python script is as follows:

import os
string = "DISPLAY=:0 xdg-open http://www.google.com"
os.system(string)

It returns the error: xdg-open: no method available for opening 'http://www.google.com'

However if I type DISPLAY=:0 xdg-open http://www.google.com into LXTerminal is works fine. It also works remotely through SSH.

Any Ideas? Also can someone explain to me why a command works fine in terminal, but not when you try to call them from a Python script using os.system()?

UPDATE -- NEED HELP STILL

NOTE: All files are located in /home/pi

After much frustration, I figured I would give the below method a try. I created a file called google.sh. The code for google.sh s as follows:

#google.sh    
DISPLAY=:0 xdg-open http://www.google.com

when I call upon this program using ./google.sh from LXTerminal it works fine! Great so now let's call it from a python script called test.py whose code is as follows:

# test.py
import os

string = "/home/pi/google.sh"
os.system(string)

However for some reason it STILL returns: xdg-open: no method available for opening 'http://www.google.com'

1

There are 1 best solutions below

0
dsncode On

how about this? the idea, is to open a epiphany window and close it after 5 seconds.

import subprocess
from time import sleep

p = subprocess.Popen("exec epiphany-browser http://yahoo.com", stdout=subprocess.PIPE,shell=True)
sleep(5)
p.kill()
print("done")