当前位置:首页 > Python教程 > python技巧

Python实现HTTP-Basic认证登陆

#!/usr/bin/python #coding:utf-8 #只限于python2.X import urllib2import jsondef httpbasic(url=None,username=None,password=None):     url = url
    username = username
    password = password
    #后面有n,需要去掉     s1 = base64.encodestring('{0}:{1}'.format(username, password))[:-1] 
    authheader =  "Basic {0}".format(s1)     res = urllib2.Request(url,{"Content-Type": "application/json","Authorization": authheader})     resp = urllib2.urlopen(res)     if __name__ == '__main__':     url = '
    username = 'httpuser'     password = 'httppass' 
    httpbasic(url, username=username, password=password) 

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐