99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀python內置的urllib模塊不支持https協(xié)議的解決辦法
python內置的urllib模塊不支持https協(xié)議的解決辦法
2017-01-05
收藏

python內置的urllib模塊不支持https協(xié)議的解決辦法

Django站點使用django_cas接入SSO(單點登錄系統(tǒng)),配置完成后登錄,拋出“urlopen error unknown url type: https”異常。尋根朔源發(fā)現(xiàn)是python內置的urllib模塊不支持https協(xié)議。


>>> import urllib
>>> urllib.urlopen(‘http://www.baidu.com’)
<addinfourl at 269231456 whose fp = <socket._fileobject object at 0xff98250>>
>>> urllib.urlopen(‘https://www.baidu.com’)
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “/usr/local/python27/lib/python2.7/urllib.py”, line 86, in urlopen
return opener.open(url)
File “/usr/local/python27/lib/python2.7/urllib.py”, line 204, in open
return self.open_unknown(fullurl, data)
File “/usr/local/python27/lib/python2.7/urllib.py”, line 216, in open_unknown
raise IOError, (‘url error’, ‘unknown url type’, type)
IOError: [Errno url error] unknown url type: ‘https’

之所以python內置的urllib模塊不支持https協(xié)議是因為編譯安裝python之前沒有編譯安裝類似于openssl這樣的SSL庫,以至于python不支持SSL

因為我用的是Centos系統(tǒng)所以安裝openssl-devel
sudo yum install openssl-devel

之后重新編譯Python
./configure(可選,因為之前已經配置過,按之前的配置來就行了,而且最好按之前的配置配編譯安裝以免依賴的庫需要重新編譯安裝。)
make
make install

>>> import urllib
>>> urllib.urlopen(‘https://www.baidu.com’)

沒有再報同樣的錯誤。

在安裝完openssl-devel后重新編譯python前也有說需要編輯Modules文件夾內Setup.dist文件的
修改
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#        -L$(SSL)/lib -lssl -lcrypto

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

但實際測試下來好像并不需要修改這個文件,編譯的時候能自動將SSL庫編譯進python中。

另外需要特別注意的是,重新編譯安裝python后,通過可執(zhí)行文件名(可能是個連接文件)運行python可能運行的還是老的python,這是因為可執(zhí)行文件名沒有連接到新的python可執(zhí)行程序。因此要用最新的python可執(zhí)行文件名或指向該名字的連接來運行python。

重新編譯安裝python后有可能導致需要重新編譯django,MySQLdb,pycrypto,python-ldap,django-auth-ldap,django_cas,django_cas,pymongo等一些列依賴python的模塊。這里要特別注意


數(shù)據分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調,回調的第一個參數(shù)驗證碼對象,之后可以使用它調用相應的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }