我在想,如果我访问使用Python的机制保护网站的密码,我会得到它需要认证数据401未授权错误。如何使用python访问受密码保护的站点?
所以我的剧本里,我试图访问我的雅虎邮箱,这显然需要用户名和密码,我想我会得到401,但我没有。
代码:
yahoo_mail = 'http://mail.cn.yahoo.com'
br = mechanize.Browser()
r = br.open(yahoo_mail)
print r.info() #here, I got 200, it's ok apparently
br.select_form(nr=0) #select the login form
r = br.submit() #submit the form without providing username and password
print r.info() #but I didn't get 401, why?
问:
- 为什么我没有拿到401无需提供身份验证,信息?
- 如果不是我的信箱,其他任何网站可以给我一个401?
我想你的意思是401未经授权,而不是410飘 – greg0ire