【发布时间】:2020-04-23 07:08:09
【问题描述】:
我的旧 CentOS 5 apache 服务器可以毫无问题地运行 Perl 脚本 CGI。
# cat t1.cgi
#!/usr/local/bin/perl
use CGI;
my $cgi = CGI->new();
print $cgi->header;
print "Test\n";
# GET HTTP://www.example.com/cgi/t1.cgi
Test
python脚本可以在shell下运行没有任何问题:
# cat t2.cgi
#!/usr/local/bin/python3
print("Content-Type: text/html\n")
print("hello!")
# python3 t2.cgi
Content-Type: text/html
hello!
但作为 python cgi 脚本失败:
# GET http://www.example.com/cgi/t2.cgi
<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
500 Internal Server Error
</BODY>
</HTML>
apache 错误日志显示错误是:
Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python
Python runtime state: preinitialized
Premature end of script headers: t2.cgi
任何想法将不胜感激!
【问题讨论】: