用 golang 當 ldap 主機 ...但 ldap client 寫不出來 ....挖哩 golang 沒有找到可用的
用 golang 呼叫 python --> ad.py 去當 ldap client
echochio 發表在 痞客邦 留言(0) 人氣(264)

import ldap
def authenticate(address, username, password):
conn = ldap.initialize('ldap://' + address)
conn.protocol_version = 3
conn.set_option(ldap.OPT_REFERRALS, 0)
try:
result = conn.simple_bind_s(username, password)
except ldap.INVALID_CREDENTIALS:
return "Invalid credentials"
except ldap.SERVER_DOWN:
return "Server down"
except ldap.LDAPError, e:
if type(e.message) == dict and e.message.has_key('desc'):
return "Other LDAP error: " + e.message['desc']
else:
return "Other LDAP error: " + e
finally:
conn.unbind_s()
return "Succesfully authenticated"
echochio 發表在 痞客邦 留言(0) 人氣(95)
程式參考 https://github.com/chio-nzgft/python-data/blob/master/test_class.py
https://github.com/chio-nzgft/python-data/blob/master/test_class2.py
echochio 發表在 痞客邦 留言(0) 人氣(8)
import json
import urllib
print sum(x['count'] for x in json.loads(str(urllib.urlopen('http://python-data.dr-chuck.net/comments_349706.json').read()))['comments'])
echochio 發表在 痞客邦 留言(0) 人氣(81)
python 換成 3.3 有點不習慣
import urllib.parse
import urllib.request
import json
echochio 發表在 痞客邦 留言(0) 人氣(11)

import urllib
import json
serviceurl = 'http://maps.googleapis.com/maps/api/geocode/json?'
echochio 發表在 痞客邦 留言(0) 人氣(57)
沒幾行程式寫了快一小時
echochio 發表在 痞客邦 留言(0) 人氣(79)
安裝 pip & matplotlib &numpy &dateutilpip install matplotlib
pip install matplotlib
pip install numpy
pip install dateutil
echochio 發表在 痞客邦 留言(0) 人氣(56)
試用看看 find strip float max
text = " X-DSPAM-Confidence: 0.8475 "
text = text.strip()
lg=None
ll=None
for n in "01234567890":
l = text.find(n)
if l > 0:
if lg is None:
lg=l
if ll is None:
ll=l
lg=max(lg,l)
if l<ll:
ll=l
print float(text[ll:lg+1])
echochio 發表在 痞客邦 留言(0) 人氣(5)
先寫個 html
echochio 發表在 痞客邦 留言(0) 人氣(10)