访问需要HTTP Basic Authentication认证的资源的python实现,,访问需要HTTP Bas
访问需要HTTP Basic Authentication认证的资源的python实现,,访问需要HTTP Bas
访问需要HTTP Basic Authentication认证的资源的python实现
import urllib2import sysimport reimport base64from urlparse import urlparse theurl = 'http://api.minicloud.com.cn/statuses/friends_timeline.xml' username = 'qleelulu'password = 'XXXXXX' # 你信这是密码吗? base64string = base64.encodestring( '%s:%s' % (username, password))[:-1] #注意哦,这里最后会自动添加一个\nauthheader = "Basic %s" % base64stringreq.add_header("Authorization", authheader)try: handle = urllib2.urlopen(req)except IOError, e: # here we shouldn't fail if the username/password is right print "It looks like the username or password is wrong." sys.exit(1)thepage = handle.read()
相关内容
- python设置socket的超时时间,pythonsocket超时,在使用urlli
- python卸载模块,python卸载,在python中如果不再
- python的is运算符,pythonis运算符,python的is运算符
- python模拟ajax请求,获得ajax请求响应,pythonajax,有些网站
- python修改mp3 专辑,作者等信息,pythonmp3,使用python修改
- python合并文件代码,python合并代码,from glob im
- python计算过去多长时间,python计算多长时间,python的日期
- python将微软InfoPath文件转换为csv文件,,InfoPath是xml
- python中使用enum的最佳实践,enum最佳实践,python中默认没
- python setattr使用示例,pythonsetattr示例,python中可以使用
评论关闭