(Raspbian Buster, Apache2, PHP 7, Python 3, Geckodriver 0.23)
I have a python script which is called by a php script with shell_exec(). When I run the python script from terminal while in the same location as the php script, it works like a charm. But when I access my apache server with localhost, the php works, but the python script does not run.
I did some researching and I found the php error log also gives my python errors. It says that I need to put my geckodriver in PATH (see below), which it is and also works when I run it within terminal but suddenly it does not when run from within php. It cannot be from any permission problems, I gave all the owner rights to the www-data group.
Error:
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
PHP code:
if ($_SESSION["loaded"] == False) {
$output = shell_exec('python3 py/infoam.py');
$_SESSION["loaded"] = True;
} elseif ($_SESSION["agendanr"] == 0 and $_SESSION["magisternr"] == 0) {
$output = shell_exec('python3 py/infoam.py');
} elseif ($_SESSION["agendanr"] == 1 and $_SESSION["magisternr"] == 0) {
$output = shell_exec('python3 py/infona.py');
} elseif ($_SESSION["agendanr"] == 0 and $_SESSION["magisternr"] == 1) {
$output = shell_exec('python3 py/infonm.py');
} else {
$output = shell_exec('python3 py/infonam.py');
}
The related python code:
from __future__ import print_function
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import requests
import time
import pickle
import os.path
headers = {"User-agent":"*my user agent*"}
class client:
def __init__(self, usr, pwd):
self.usr = usr
self.pwd = pwd
def magister(self):
driver = webdriver.Firefox()
driver.get("https://farel.magister.net/magister/#/vandaag")
driver.maximize_window()
driver.implicitly_wait(20)
time.sleep(5)
elem = driver.find_element_by_id("username")
elem.send_keys(self.usr)
elem.send_keys(u'\ue007')
driver.maximize_window()
driver.implicitly_wait(20)
elem = driver.find_element_by_id("rswp_password")
elem.send_keys(self.pwd)
elem.send_keys(u'\ue007')
driver.maximize_window()
driver.implicitly_wait(10)
time.sleep(5)
elem = driver.find_element_by_class_name("last-grade").text
lis = elem.split()
grade, clas = lis[0], lis[1]
driver.quit()
return(grade + '\n' + clas + '\n')
def write(self):
file = '/var/www/html/txt/' + self.usr + '.txt'
with open(file, 'w') as writefile:
writefile.write(self.magister())
def read():
f = open("/var/www/html/txt/acc.txt", "r")
for x in f:
keys = []
for y in x.split(','):
keys.append(y.strip())
print(keys)
person = client(keys[0], keys[1])
person.write()
read()
Does anybody know why it throws this error?