无法使用XAMPP从Python cgi脚本写入PYTHON_EGG_CACHE

时间:2015-10-28 17:33:31

标签: python xampp cgi

我有这个简单的脚本通过ssh连接到服务器,如果我从shell运行脚本它可以工作,但是当我从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

我在Windows上使用XAMPP,我编辑了httpd.conf以接受来自cgi-bin的.py文件,实际上是一个简单的

#!C:\Python27\python

print "Content-type: text/html\n\n"
print "Test"

在浏览器中运行。

我的Apache日志中发现的错误如下:

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.

提前致谢

1 个答案:

答案 0 :(得分:0)

一个开始的地方是将paramiko(和其他依赖项,如果这个错误重现)直接安装到你现有的Python安装中,这样就不需要将它作为一个egg下载和提取(因此不需要文件)适合该任务的权限)。例如:

c:\Python\Scripts\easy_install.exe --always-unzip paramiko

允许您的Web服务器写入存储代码的位置(并且Python鸡蛋是代码!)是非常糟糕的安全实践(在妥协时,攻击者可以将自己的内容放在那里,并且在paramiko或者其他库已加载。)