2

When I run python deamon.py, the test suite runs properly; however, when I run it with /usr/bin/python it throws a warning for a Casper.waitfor() timeout as it apparently can't read the DOM elements.

// Fails:
/usr/bin/python  /path_to_deals/deals/deamon.py

// Succeeds:
python  /path_to_deals/deals/deamon.py

Below is the directory structure:

deals/

 deamon.py
 test.js

deamon.py is the script which initiates the casperjs test suite in the test.js file.

Can any one explain why python works but /usr/bin/python does not -- and how I might fix this?

Update from discussion: "When I do python deamon.py it fails only when I put it in a Cron (where I have to specify the exact python path as well as the script path)."

Community
  • 1
  • 1
Somesh
  • 1,235
  • 2
  • 13
  • 29

1 Answers1

2

As Arcege explains here, "Cron knows nothing about your shell; it is started by the system, so it has a minimal environment. If you want anything, you need to have that brought in yourself."

Most likely, there is some variable that is set in your session that is being forgotten by Cron. Here are three options:

1.) You could either set the environmental variables for a specific command as Nischal does here.

Gist:

* * * * * . $HOME/.profile; python /path/to/myScript.py

2.) Set the an environmental variable for the entire Crontab as they do here.

Gist:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * *   python /path/to/myScript.py

(More on setting environmental variables in Cron.)


3.) Set the environmental variables in the script itself. Python's urllib2 apparently needs the http_proxy variable, so if you're using that you might have a problem. You could use os to set it (source) or -- what might be better -- you could specify the proxy that urllib2 should use as ZelluX does here with a ProxyHandler.

Gist:

proxy = urllib2.ProxyHandler({'http': '127.0.0.1'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
urllib2.urlopen('http://www.example.com')
Community
  • 1
  • 1
Casey Falk
  • 2,617
  • 1
  • 18
  • 29