0

I need help authenticating logging into this site using urllib. I am using python 3, but I'm willing to revert to 2.x. This is what I have sofar (basically from the documentation), it gives not errors, but its not logging in.

file =open("loggedinsource.html",'wb')

# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='kalahari.net',uri='https://www.kalahari.net/profile/pipeline/signin.aspx?',user='myuser',passwd='mypass')

opener = urllib.request.build_opener(auth_handler)

# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)
f=urllib.request.urlopen('https://www.kalahari.net/profile/pipeline/signin.aspx?')

page=f.read()
file.write(page);
file.close()

I have been struggling with this for ages, any help please.

2
  • We can help with code questions, but not with "struggling". Do you even know that you need basic HTTP auth? Most websites use sessions/cookies ... Commented Feb 28, 2011 at 21:20
  • 3
    Just tried visiting the URL in the OPs code, and it's using a form to capture user/pass, not HTTP basic auth. Commented Feb 28, 2011 at 21:48

1 Answer 1

1

The site you are trying to log into is not using HTTP basic auth; it is using a regular HTML form.

If you want to log into something like this, you probably want to look at something like mechanize

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I had no idea about the need for HTTP Auth or not, pretty new to python and web programming. thanks I will look into mechanize and I heard ClientForm can be useful too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.