繁体   English   中英

Python“导入请求”返回500 Internal Server Error

[英]Python “import request” returns 500 Internal Server Error

我在让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>

error_log中:

    [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'

您似乎正在使用旧版本的请求。

除非您有理由不这样做,否则请尝试将请求升级到最新版本:

$ pip install --upgrade requests

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

pip install --upgrade requests无法正常工作,但我必须手动删除请求目录,然后重新启动服务器。

之后,我通过pip install requests重新pip install requests

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM