Previous Research:
- Running a Python script from PHP
- error on using exec() to call python script
- Php exec python script 'weakness'/downside
- Using exec() to run python script in PHP
I am running php version 5.6.6 and python version 3.4.3 on OS X.
Basically, the problem that I am running into is that if I run a python script via command line it works find but if I run it through a PHP script (using exec()
) I get this error:
AttributeError: type object 'int' has no attribute 'from_bytes'
I have created and tested a miniature isolated test case to show the problem. I have already done a chmod 777 mypy.py
to make sure mypy.py is executable.
myphp.php:
<?php
exec("/usr/bin/python mypy.py 1A", $output, $return);
var_dump($output);
mypy.py:
#!/usr/bin/env python
import string
import array
import binascii
import sys
if __name__ == "__main__":
hexval = sys.argv[1]
binval = binascii.unhexlify(hexval)
binint = int.from_bytes(binval, byteorder='big', signed=False)
print("int: " + str(binint))
(I know there are better ways to accomplish what is being done in this python script, I was just making a test case that would produce the same error)
When I run python mypy.py 1F
via command line, I get this printed:
int: 31
But when I run php myphp.php
via command line, I get this printed:
Traceback (most recent call last):
File "mypy.py", line 11, in <module>
binint = int.from_bytes(binval, byteorder='big', signed=False)
AttributeError: type object 'int' has no attribute 'from_bytes'
array(0) {
}
(Note: I have also executed whoami
from the php script just to verify that my normal user is the one running the python script)