Score:1

Simple PHP calling Python script - Call not working

ag flag

I've got a simple localhost website with a php page that has some buttons on it that call python scripts.

I can run it locally and the output works so standalone the scrip is fine. The issue is with the import function. Whenever I add an import, it breaks

I had it workining on an older laptop with a previous PHP and Python version.

Any thoughts

Here is the php

<?php
 $command = escapeshellcmd("/usr/bin/python3 test-py.py");
 $output = shell_exec($command);
 echo $output;
 ?>

here is the simple python whois to a output file

import sys
import whois

if len(sys.argv) != 2:
    print("Usage: python whois_ip.py <ip_address>")
    sys.exit(1)

ip_address = sys.argv[1]
w = whois.whois(ip_address)

with open("output.txt", "w") as f:
f.write(str(w))

print("WHOIS lookup results written to output.txt")

My questions are 1 Any thoughts why the import function no longer works? Could it be a permissions issue with importing libraries? 2 My PHP.ini has disabled_functions = "" (so nothing is disabled right?) 3 Is there something special about PHP 8.2.5 and Python 3.9.6 that I should be aware of?

Appreciate any and all help on this. Thanks

in flag
Please don't cross post. Development questions are off topic here.
eezetee avatar
ag flag
Not sure about a cross post as this is the only post with these questions. This is for a system that was working, now is not. Where else would I ask these questions? Thanks
eezetee avatar
ag flag
Per the StackOverflow FAQ. Stack Overflow is for professional and enthusiast programmers, or anyone who writes code because they love it. The best Stack Overflow questions generally have a bit of source code in them, but if your question generally covers… a specific programming problem, or a software algorithm, or software tools commonly used by programmers; and is a practical, answerable problem that is unique to software development …then you’re in the right place to ask your question!
eezetee avatar
ag flag
If anyone can help with my question on previously working code that no longer works, i'd greatly appreciate it. THank you for your time
eezetee avatar
ag flag
Really looking forward to any suggestions. I've been spinning around on this for days
eezetee avatar
ag flag
I've gotten a little farther today... It seems that the buttons work and the scripts are executed but doing a "import whois" or "import sys" breaks it. Anyone with an guess on what it could be?
eezetee avatar
ag flag
Tried looking at libraries and packages inside python3, seems they are the same...
Score:0
ag flag

I have found my solution and sharing here.

Inside my XAMPP config file, there is the httpd.conf where you set the user. Mine was set to daemon. I changed it to my local username and staff is the group. That allows the extra functions of my script to work.

Sharing here for others that may have similar issues.

In short, it was a permissions issue with the user that was running httpd

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.