471,330 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

using urllib, urllib2 ,mechanize to access password protected site

Hi

I am using this script to access doba.com (I need to download some
files) but I keep on being sent back to the login page not the user
home page. Any help. I think I may need to use a post method and
opener is using a get method

Thanks

import mechanize
cookies = mechanize.CookieJar()
# build_opener() adds standard handlers (such as HTTPHandler and
# HTTPCookieProcessor) by default. The cookie processor we supply
# will replace the default one.
opener =
mechanize.build_opener(mechanize.HTTPCookieProcess or(cookies))
opener.addheaders = [("User-agent", "Mozilla/5.0 (Windows; U; Windows
NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"), ]
data="username=user&password=pw"
#r = opener.open("http://comeshopcheap.com/") # GET
r = opener.open("https://www.doba.com/members/login.php", data) # POST

Jun 28 '07 #1
1 3799
comeshopcheap <mo**********@gmail.comwrites:
Hi

I am using this script to access doba.com (I need to download some
files) but I keep on being sent back to the login page not the user
home page. Any help. I think I may need to use a post method and
opener is using a get method

Thanks

import mechanize
cookies = mechanize.CookieJar()
# build_opener() adds standard handlers (such as HTTPHandler and
# HTTPCookieProcessor) by default. The cookie processor we supply
# will replace the default one.
opener =
mechanize.build_opener(mechanize.HTTPCookieProcess or(cookies))
opener.addheaders = [("User-agent", "Mozilla/5.0 (Windows; U; Windows
NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"), ]
data="username=user&password=pw"
#r = opener.open("http://comeshopcheap.com/") # GET
r = opener.open("https://www.doba.com/members/login.php", data) # POST
You shouldn't need to worry re POST and GET.

Visiting the login page is presumably not enough in itself to log you
in. So, what are you doing to ensure you're logged in?

Probably you want to fill in and submit the login form on the login
page. Alternatively, use e.g. mechanize.MozillaCookieJar and load
cookies from your web browser (this option requires that you are
already logged in persistently, though, so I'd suggest filling in the
login form as the safe option).
John
Jul 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Max Khesin | last post: by
4 posts views Thread by bmiras | last post: by
3 posts views Thread by Volker M. | last post: by
reply views Thread by Pieter Edelman | last post: by
1 post views Thread by onceuponapriori | last post: by
3 posts views Thread by Alexnb | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.