我很难让python 2.7.5在我的CentOS7服务器上工作。测试打印不是问题,但是当我尝试导入请求时会中断。我不懂te error_log。我现在不知道该怎么办。请帮忙:)
是的请求已安装,我已三重检查。
我的代码:
import requests
结果:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at
root@localhost to inform them of the time this error occurred,
and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>
错误日志:
[Mon Jan 21 20:11:54.179538 2019] [:error] [pid 16293] [client 84.85.100.198:32770] PythonHandler mod_python.cgihandler: Traceback (most recent call last):
[Mon Jan 21 20:11:54.179578 2019] [:error] [pid 16293] [client 84.85.100.198:32770] PythonHandler mod_python.cgihandler: File "/usr/lib64/python2.7/site-packages/mod_python/apache.py", line 398, in HandlerDispatch\n result = obj(req)
[Mon Jan 21 20:11:54.179586 2019] [:error] [pid 16293] [client 84.85.100.198:32770] PythonHandler mod_python.cgihandler: File "/usr/lib64/python2.7/site-packages/mod_python/cgihandler.py", line 96, in handler\n imp.load_module(module_name, fd, path, desc)
[Mon Jan 21 20:11:54.179592 2019] [:error] [pid 16293] [client 84.85.100.198:32770] PythonHandler mod_python.cgihandler: File "/var/www/vhosts/vps-139083-2773.hosted.at.hostnet.nl/regt/test.py", line 23, in <module>\n import requests
[Mon Jan 21 20:11:54.179598 2019] [:error] [pid 16293] [client 84.85.100.198:32770] PythonHandler mod_python.cgihandler: File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 53, in <module>\n from .packages.urllib3.contrib import pyopenssl
[Mon Jan 21 20:11:54.179605 2019] [:error] [pid 16293] [client 84.85.100.198:32770] PythonHandler mod_python.cgihandler: File "/usr/lib/python2.7/site-packages/requests/packages/__init__.py", line 61, in load_module\n if name in sys.modules:
[Mon Jan 21 20:11:54.179628 2019] [:error] [pid 16293] [client 84.85.100.198:32770] PythonHandler mod_python.cgihandler: AttributeError: 'NoneType' object has no attribute 'modules'
答案 0 :(得分:0)
您似乎正在使用旧版本的请求。
除非您有理由不这样做,否则请尝试将请求升级到最新版本:
static func GetSelectedSessionNum() -> Int32 {
var sessionNum : Int32 = 0
let defaults = UserDefaults.standard
let optionalString: String? = defaults.string(forKey: "selectedSessionNum")
// this works but it's too complicated
if let string = optionalString, let myInt = Int32(string) {
return myInt
}
return 0
// Error : optional String? must be unwrapped to a value of type 'String'
let t : String = defaults.string(forKey: "selectedSessionNum")
if let s : String = defaults.string(forKey: "selectedSessionNum") {
// error - Int32? must be unwrapped to a value of Int32
return Int32(s)
}
return 0
}
答案 1 :(得分:0)
感谢Benton Snyder,我解决了这个问题。
pip install --upgrade requests
无效,但是我必须手动删除请求目录,然后重新启动服务器。
之后,我通过pip install requests