林家访*_*林家访 5 python ssl https httpserver
我的http服务器基于BaseHTTPServer和Python 2.7.6.现在我希望它支持ssl传输,所谓的https.
我已经安装了pyOpenSSL并使用ssl支持重新编译了python源代码.当我尝试import ssl使用我的python解释器时,它确实有效,但是当我在服务器上运行代码时,它不起作用.错误日志是这样的:
import _ssl#如果我们无法导入它,让错误传播
看起来很奇怪,不是吗?我的操作系统是Debian Linux发行版.我已经尝试过各种各样的方法,我可以在互联网上找到几天,有谁可以帮助我摆脱这个麻烦?
我试图直接在服务器代码中"导入_ssl",但它提醒我:
>>>callstack
Traceback (most recent call last):
File "./script/main.py", line 85, in process
net_flag = net_api_process()
File "./script/core/netbase/interface.py", line 96, in net_api_process
flag1 = network.instance().process()
File "./script/core/netbase/network.py", line 271, in process
if network.process(max_events):
File "./script/core/netbase/network.py", line 75, in on_incomin_stream
self.on_package(buf)
File "./script/core/netbase/network.py", line 78, in on_package
self.f_on_package(self, buf)
File "./script/client/behavior.py", line 68, in on_package
handler.OnPackage(pack, cmd, conn.m_uid, conn)
File "./script/client/handler.py", line 288, in OnPackage
func(uid, conn, pack)
File "./script/logic/user_info/modify.py", line 365, in OnModBaseInfo
ModBaseInfo(uid, conn, seq, json_str)
File "./script/logic/user_info/modify.py", line 385, in ModBaseInfo
modify_pub.Start()
File "./script/logic/user_info/modify.py", line 253, in Start
import _ssl
ImportError: No module named _ssl
Run Code Online (Sandbox Code Playgroud)
我终于解决了这个问题!\n_ssl 模块是 python 的内置模块,但它需要在您的系统上安装 openssl。
\n\n首先更改为 root 用户!\n1.安装 openssl 和 libssl-dev。\n如果在 debian 操作系统上
\n\napt-get install openssl\napt-get install libssl-dev\nRun Code Online (Sandbox Code Playgroud)\n\n2.重新编译python
\n\ncd Python2.7.6\n./configure\nmake && make install\nRun Code Online (Sandbox Code Playgroud)\n\n但实际上,我是这样解决问题的!\n1.安装openssl\n我从网上下载了一个包,是openssl-1.0.2d.tar.gz
\n\ntar zxvf openssl-1.0.2d.tar.gz\ncd openssl-1.0.2d\n./config -fPIC //configuration\xef\xbc\x9acreate path independent libssl.a\nmake && make install\nRun Code Online (Sandbox Code Playgroud)\n\n2.重新编译python2.7,并使其支持ssl模块
\n\ntar xvf Python-2.7.6.tar\ncd Python-2.7.6\nvim Modules/Setup.dist \nRun Code Online (Sandbox Code Playgroud)\n\n找到以下行并取消注释。(使用 /ssl+Enter 在 vim 中快速找到这些行)
\n\n# Socket module helper for socket(2)\n_socket socketmodule.c timemodule.c\n\n# Socket module helper for SSL support; you must comment out the other\n# socket line above, and possibly edit the SSL variable:\nSSL=/usr/local/ssl\n_ssl _ssl.c \\\n -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \\\n -L$(SSL)/lib -lssl -lcrypto\nRun Code Online (Sandbox Code Playgroud)\n\n然后config和make,make install
\n\n./configure --enable-shared //--enable-shared option means to generate dynamic library libpython2.7.so.1.0\nmake && make install\nRun Code Online (Sandbox Code Playgroud)\n\n我们的项目依赖于libpython2.7.so.1.0。现在我可以使用新的 libpython2.7.so.1.0 在 python 脚本或 python 解释器中成功“导入 ssl”或“导入 _ssl”。
\n| 归档时间: |
|
| 查看次数: |
12053 次 |
| 最近记录: |