python - 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'
解决方案
感谢 Benton Snyder,我解决了这个问题。
pip install --upgrade requests
不起作用,但我不得不手动删除请求目录,然后重新启动我的服务器。
之后我通过重新安装pip install requests
推荐阅读
- node.js - 包含混合内容的数组不起作用。反应
- python - 将 2 个列表与 .intersection() 进行比较
- centos7 - centos firewall-cmd 端口转发到目标端口范围不起作用
- nattable - Nattable 按钮单击排序,放置在列标题上
- python - 如何读取 csv 行并使用 pandas 转换为数据框列?
- javascript - 无法读取未定义的属性“myHub”(SignalR)
- c# - 避免对特定表行进行 sql 连接
- javascript - 客户端使用 tornado wtforms 的 Selectize.js 搜索功能
- python - 使用 zbar python 的条码检测不适用于所有文档
- indexing - 如何在矩阵维度中使用实数数组索引?