无法使用 XAMPP 从 Python cgi 脚本写入 PYTHON_EGG_CACHE
Can't write to PYTHON_EGG_CACHE from Python cgi script using XAMPP
我有这个简单的脚本可以通过 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.
提前致谢
一个开始的地方是将 paramiko(以及其他依赖项,如果此错误再次出现)直接安装到您现有的 Python 安装中,这样就不需要将其下载并提取为 egg (因此不需要适合该任务的文件权限)。例如:
c:\Python\Scripts\easy_install.exe --always-unzip paramiko
允许您的 Web 服务器写入存储代码的位置(Python eggs 是代码!)是非常糟糕的安全做法(妥协后,攻击者可以将自己的内容放在那里,并它总是 运行 当加载 paramiko 或其他库时。
我有这个简单的脚本可以通过 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.
提前致谢
一个开始的地方是将 paramiko(以及其他依赖项,如果此错误再次出现)直接安装到您现有的 Python 安装中,这样就不需要将其下载并提取为 egg (因此不需要适合该任务的文件权限)。例如:
c:\Python\Scripts\easy_install.exe --always-unzip paramiko
允许您的 Web 服务器写入存储代码的位置(Python eggs 是代码!)是非常糟糕的安全做法(妥协后,攻击者可以将自己的内容放在那里,并它总是 运行 当加载 paramiko 或其他库时。