473,566 Members | 3,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Cooki eJar()
# build_opener() adds standard handlers (such as HTTPHandler and
# HTTPCookieProce ssor) by default. The cookie processor we supply
# will replace the default one.
opener =
mechanize.build _opener(mechani ze.HTTPCookiePr ocessor(cookies ))
opener.addheade rs = [("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=p w"
#r = opener.open("ht tp://comeshopcheap.c om/") # GET
r = opener.open("ht tps://www.doba.com/members/login.php", data) # POST

Jun 28 '07 #1
1 3940
comeshopcheap <mo**********@g mail.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.Cooki eJar()
# build_opener() adds standard handlers (such as HTTPHandler and
# HTTPCookieProce ssor) by default. The cookie processor we supply
# will replace the default one.
opener =
mechanize.build _opener(mechani ze.HTTPCookiePr ocessor(cookies ))
opener.addheade rs = [("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=p w"
#r = opener.open("ht tp://comeshopcheap.c om/") # GET
r = opener.open("ht tps://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.Mozil laCookieJar 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
7070
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 - max@cNvOiSsPiAoMntech.com www.cvisiontech.com, JBIG2-PDF compression @
4
4448
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 python 2.3 Here is an exemple of the piece of code I use: import urllib2 #Proxy handler proxy_handler = urllib2.ProxyHandler({"http" :
3
2024
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 user/password-request. So exists a possibility that I could cancel all site requests with user/password-dialogues? Thx
0
3571
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 my cry for help. The server is an elog logbook server (http://midas.psi.ch/elog/). It is protected with a password and an empty username. I can...
1
1578
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". I try again and the second time i succeed,judging from the output of line "8". Now using the "twill" module...
1
2573
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 post to the login.php page, there seems to be a redirect and it seems that the site is using a session (perhaps a cookie) to determine whether the...
3
19543
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 password at the terminal. Is there any way to do this non-interactively? To hardcode the user/ pass into the script so I can get the page...
3
1948
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: class=r>.*?</h2>', -- View this message in context: http://www.nabble.com/using-urllib2-tp18150669p18160312.html
0
3477
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 trying to login is http://www.princetonreview.com/Login3.aspx?uidbadge= user: bugmenot2008@yahoo.com pass: letmeinalready Previously I did...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.