【问题标题】:linux apache python cgi error: failed to get random numbers to initialize Pythonlinux apache python cgi错误:无法获取随机数来初始化Python
【发布时间】: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

任何想法将不胜感激!

【问题讨论】:

    标签: python apache cgi


    【解决方案1】:

    修复它

    mknod -m 444 /dev/random
    chmod 444 /dev/urandom
    

    我的旧centos没有/dev/random,urandom的默认文件模式是600,只有root才能读取。

    【讨论】:

      猜你喜欢
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 2023-03-08
      • 1970-01-01
      相关资源
      最近更新 更多