I have a Python script that uses urllib2 to retrieve data from an external site. I am on a corporate network that requires proxy authentication.
While on command line, I am able to export the proxy settings in the .bashrc to allow the script to exit via the proxy and make the request.
So the script does work from behind the proxy.
Here is the problem: I need to call this Python script from a php script on a website. I have tried several ways to achieve this by calling the script with: exec(), popen(), shell_exec()
I can't get the script to return any results. When tailing /var/log/httpd/error** I can see the error being generated:
urllib2.URLError: <urlopen error [Errno 110] Connection timed out>, referer:
This is the same error that I received before setting the proxy in the .bashrc
I have suPHP set up and configured to run scripts as a particular user. I have also set all files including the python script to be owned by this user, and also adjusted permissions, trying +x and also insecurely setting to 777 just for testing purposes.
I can run a a php script from the same directory from the website, and verify Apache is running under this user with a simple:
echo exec('whoami');
I can also execute a simple Python script from this same PHP page with the same setup that only prints to stdout and I can return that value back to the webpage, so I know I can execute Python scripts with this method.
When in command line, I su to the same user that has been established as the user that Apache runs under and set the proxy in that account, but still, the script does not execute correctly when executing from the web page, still only works in CLI.
Just to test, I added a line to write to a file in the Python script with the intent to just write the data to that file that I needed returned, thinking that I could just read that file in afterwards. What I noticed is that, the creation of the files works, but no data is written to it since the urllib2 code times out and never writes to the file.
Any idea how to make my PHP script execute this Python script that needs Proxy access?
Do I need to explicitly tell urllib2 to use a proxy? The urllib2 routine that I am using is part of a Python module that is coded to just use the OS's proxy settings, and again, I know it works, since I can execute this under the Apache user from CLI.
Any help is greatly appreciated.