472,952 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 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 3908
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Max Khesin | last post by:
Is there a way to access an htaccess-protected directory with urllib, password being known? thanks, max -- ======================================== Max Khesin, software developer -...
4
by: bmiras | last post by:
I've got a problem using urllib2 to get a web page. I'm going through a proxy using user/password authentification and i'm trying to get a page asking for a HTTP authentification. And I'm using...
3
by: Volker M. | last post by:
Hey, I want to open a list of URLs with Pythons urllib and the fuction open(URL) automatically. It is important that the program open ONLY normal http-sites and no https-sites with...
0
by: Pieter Edelman | last post by:
Hi all, I'm trying to submit some data using a POST request to a HTTP server with BASIC authentication with python, but I can't get it to work. Since it's driving me completely nuts, so here's...
1
by: jnair | last post by:
Hi , I am using python2.4 "urllib2" and "cookelib". In line "5" below i provide my credentials to login into a web site.During the first attempt i "fail", judging from the output of line "6"....
1
by: onceuponapriori | last post by:
Greetings gents. I'm a Railser working on a django app that needs to do some scraping to gather its data. I need to programatically access a site that requires a username and password. Once I...
3
by: rodrigo | last post by:
I am trying to retrieve a password protected page using: get = urllib.urlopen('http://password.protected.url"').read() While doing this interactively, I'm asked for the username, then the...
3
by: Alexnb | last post by:
Okay, I tried to follow that, and it is kinda hard. But since you obviously know what you are doing, where did you learn this? Or where can I learn this? Maric Michaud wrote:...
0
by: trihaitran | last post by:
I am trying to write a web scraper and am having trouble accessing pages that require authentication. I am attempting to utilise the mechanize library, but am having difficulties. The site I am...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.