ssl - How to import _ssl in python 2.7.6? -


my http server based on basehttpserver python 2.7.6. want support ssl transportation, called https.

i have installed pyopenssl , recompiled python source code ssl support. , work when try import ssl in python interpreter, doesn't work when run code on server. error log this:

import _ssl # if can't import it, let error propagate

it looks quite strange, doesn't it? operating system debian linux distribution. have tried kinds of ways can find on internet days, can me out of trouble?


i tried "import _ssl" in server code directly, reminds me this:

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

i fixed problem finally! _ssl module built-in module python, requires openssl installed on system.

change root user first! 1.install openssl , libssl-dev. if on debian os

apt-get install openssl apt-get install libssl-dev 

2.recompile python

cd python2.7.6 ./configure make && make install 

but actually, fix problem in way! 1.install openssl download package internet, openssl-1.0.2d.tar.gz

tar zxvf openssl-1.0.2d.tar.gz cd openssl-1.0.2d ./config -fpic   //configuration:create path independent libssl.a make && make install 

2.recompile python2.7, , make support ssl module

tar xvf python-2.7.6.tar cd python-2.7.6 vim modules/setup.dist  

find following line , uncomment it.(use /ssl+enter locate these lines in vim)

# socket module helper socket(2) _socket socketmodule.c timemodule.c  # socket module helper ssl support; must comment out other # socket line above, , possibly edit ssl variable: ssl=/usr/local/ssl _ssl _ssl.c \         -duse_ssl -i$(ssl)/include -i$(ssl)/include/openssl \         -l$(ssl)/lib -lssl -lcrypto 

and config , make, make install

./configure --enable-shared //--enable-shared option means generate dynamic library libpython2.7.so.1.0 make && make install 

our project depends on libpython2.7.so.1.0. can "import ssl" or "import _ssl" in python script or python interpreter new libpython2.7.so.1.0.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -