Mechanize/OWA user/password error

巧了我就是萌 提交于 2019-12-08 13:39:28

问题


I'm trying to use Mechanize to get emails from my Outlook web client, but I'm having troubles logging in. It gives me the errors listed below. I've verified that the user name and password are correct. Any ideas?

Here is my code:

import mechanize

b = mechanize.Browser()
cj = cookielib.LWPCookieJar()
b.set_cookiejar(cj)

b.open('https://mail.example.com/owa/')
br.select_form("logonForm")
b['username'] = 'myname'
b['password'] = 'password'
b.submit()

I can see that form components are being accessed correctly, but after submitting, the login page displays again with two errors:

  1. The user name or password you entered isn't correct. Try entering it again.
  2. Please enable cookies for this Web site.

I thought the b.set_cookiejar(cj) would take care of cookies. Could this be the root of my problem?


回答1:


import mechanize 
import cookielib

br = mechanize.Browser()
br.set_handle_robots( False )
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

br.open('https://webmail.server.com')
br.select_form(nr = 0) 
br.form['username'] = 'username'
br.form['password'] = 'password'
br.submit()

Use this it works for me



来源:https://stackoverflow.com/questions/25612539/mechanize-owa-user-password-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!