linux apache python cgi error: failed to get random numbers to initialize Python
linux apache python cgi error: failed to get random numbers to initialize Python
我的旧 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
任何想法将不胜感激!
由
修复了它
mknod -m 444 /dev/random
chmod 444 /dev/urandom
我的旧centos没有/dev/random,urandom的默认文件模式是600,只能由root读取。
我的旧 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
任何想法将不胜感激!
由
修复了它mknod -m 444 /dev/random
chmod 444 /dev/urandom
我的旧centos没有/dev/random,urandom的默认文件模式是600,只能由root读取。