def api_login():
global token
url = settings.MASTER_API_URL_LOGIN
ch = pycurl.Curl() #????pycurl?????
ch.setopt(ch.URL, url) #??????url
info = StringIO.StringIO()
ch.setopt(ch.WRITEFUNCTION, info.write)
ch.setopt(ch.POST, True)
#???https???????
ch.setopt(ch.SSL_VERIFYPEER, 0)
ch.setopt(ch.SSL_VERIFYHOST, 2)
ch.setopt(ch.HTTPHEADER, ['Accept: application/x-yaml'])
ch.setopt(ch.POSTFIELDS, 'username=%s&password=%s&eauth=pam' %(settings.SALT_API_AUTH_USER, settings.SALT_API_AUTH_PASS))
#?????
#ch.setopt(ch.HEADER, True)
#??????
ch.setopt(ch.HEADER,False)
ch.perform()
html = info.getvalue()
#??token
token = html.split("\n")[-3].replace("\n", '')
token = token.split(' ')[3]
info.close()
ch.close()
评论列表
文章目录