python 登录验证

python请求服务器数据,验证用户名和密码,除了常用的HTTPBasicAuthHandler,还有HTTPDigestAuthHandler,可以通过fiddler抓包,查看服务器返回数据中的验证字段,如果是Digest验证,返回的格式的应该是

HTTP/1.1 401 Unauthorized
Connection: close
WWW-Authenticate: Digest qop="auth", realm="example", nonce="1444807486_3232235838"


python 请求数据的方法是:(使用urllib和urllib2)
import urllib
import urllib2
url_top = "http://www.example.com"
url = "http://www.example.com/index.html"

auth = urllib2.HTTPDigestAuthHandler()  #根据服务器要求的验证方法,选择对应的handler
auth.add_password(realm,url_top,username,password)
opener = urllib2.build_opener(auth)
urllib2.install_opener(opener)
res_data = urllib2.urlopen(url)
res = res_data.read()
print res

参考:

http://www.th7.cn/Program/Python/201411/310230.shtml

https://zindilis.com/blog/2012/08/15/login-in-to-website-with-digest-authentication-in-python.html

http://blog.163.com/hlz_2599/blog/static/1423784742013415101252410/

Basic验证和Digest验证的设置方式

http://blog.jobbole.com/41519/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值