首页 > 解决方案 > Python“导入请求”返回 500 内部服务器错误

问题描述

我在让 python 2.7.5 在我的 CentOS7 服务器上工作时遇到了很多麻烦。测试打印不是问题,但是当我尝试导入请求时它会中断。我不明白错误日志。我不知道现在该怎么办。请帮忙 :)

是的请求已安装,我检查了三次。

我的代码:

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'

标签: pythonpython-requests

解决方案


感谢 Benton Snyder,我解决了这个问题。

pip install --upgrade requests不起作用,但我不得不手动删除请求目录,然后重新启动我的服务器。

之后我通过重新安装pip install requests


推荐阅读