Access a web page with basic auth in python

I am trying to connect a mechanized webpage, but I am getting http 401 error.

Here is my code;

import base64, mechanize

url = "http://www.dogus.edu.tr/dusor/FrmMain.aspx"
user = "user"
pwd = "pwd"

br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
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.add_password(url, user, pwd)
#br.addheaders.append(('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (user, pwd))))
print br.open(url).read()

Both add_passwordand addheadersare not working. Is it because I never indicated a kingdom? How can I get in which area this web page is used? The username and password that I use are correct, as I can log in using chrome with these credentials.

+4
source share
1 answer

, , NTLM. , HEADER. , curl -I http://www.dogus.edu.tr/dusor/FrmMain.aspx :

HTTP/1.1 401 Unauthorized
Content-Length: 1293
Content-Type: text/html
Server: Microsoft-IIS/7.0
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
X-Powered-By: ASP.NET
Date: Mon, 07 Apr 2014 21:24:09 GMT

WWW-Authenticate: NTLM , . , python NTLM .

+2

Source: https://habr.com/ru/post/1535345/


All Articles