I have this simple script to connect via ssh to a server and it works if I run the script from shell, but it doesn't when I call the script from cgi-bin (http://localhost/cgi-bin/test.py)
#!C:\Python27\python
print "Content-type: text/html\n\n"
import spur
shell = spur.SshShell(hostname="192.168.1.5", username="user", password="pass", missing_host_key=spur.ssh.MissingHostKey.accept)
result = shell.run(["pwd"])
print result.output
I'm using XAMPP on Windows and I edited the httpd.conf to accept .py files from cgi-bin, infact a simple
#!C:\Python27\python
print "Content-type: text/html\n\n"
print "Test"
works in browser.
The error found in my Apache logs is as follows:
Traceback (most recent call last):
File "C:/xampp/cgi-bin/smart.py", line 4, in <module>
import spur
File "C:\\Python27\\lib\\site-packages\\spur\\__init__.py", line 2, in <module>
from spur.ssh import SshShell
File "C:\\Python27\\lib\\site-packages\\spur\\ssh.py", line 15, in <module>
import paramiko
File "build\\bdist.win32\\egg\\paramiko\\__init__.py", line 30, in <module>
File "build\\bdist.win32\\egg\\paramiko\\transport.py", line 49, in <module>
File "build\\bdist.win32\\egg\\paramiko\\dsskey.py", line 26, in <module>
File "build\\bdist.win32\\egg\\Crypto\\PublicKey\\DSA.py", line 89, in <module>
File "build\\bdist.win32\\egg\\Crypto\\Random\\__init__.py", line 28, in <module>
File "build\\bdist.win32\\egg\\Crypto\\Random\\OSRNG\\__init__.py", line 34, in <module>
File "build\\bdist.win32\\egg\\Crypto\\Random\\OSRNG\\nt.py", line 28, in <module>
File "build\\bdist.win32\\egg\\Crypto\\Random\\OSRNG\\winrandom.py", line 7, in <module>
File "build\\bdist.win32\\egg\\Crypto\\Random\\OSRNG\\winrandom.py", line 4, in __bootstrap__
File "C:\\Python27\\lib\\site-packages\\pkg_resources\\__init__.py", line 1155, in resource_filename
self, resource_name
File "C:\\Python27\\lib\\site-packages\\pkg_resources\\__init__.py", line 1851, in get_resource_filename
self._extract_resource(manager, self._eager_to_zip(name))
File "C:\\Python27\\lib\\site-packages\\pkg_resources\\__init__.py", line 1881, in _extract_resource
self.egg_name, self._parts(zip_path)
File "C:\\Python27\\lib\\site-packages\\pkg_resources\\__init__.py", line 1221, in get_cache_path
self.extraction_error()
File "C:\\Python27\\lib\\site-packages\\pkg_resources\\__init__.py", line 1201, in extraction_error
raise err
pkg_resources.ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Error 5] Accesso negato: 'C:\\\\Windows\\\\Application Data'
The Python egg cache directory is currently set to:
C:\\Windows\\Application Data\\Python-Eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
Thanks in advance