473,612 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Entering username & password automatically using urllib.urlopen

I am trying to retrieve a password protected page using:

get = urllib.urlopen( 'http://password.protec ted.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 automatically?

(This is not a cracking attempt, I am trying to retrieve a page I have
legitimate access to, just doing it automatically when certain
conditions are met.)

Thanks,

Rodrigo

Oct 14 '07 #1
3 19573
rodrigo schrieb:
I am trying to retrieve a password protected page using:

get = urllib.urlopen( 'http://password.protec ted.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 automatically?

(This is not a cracking attempt, I am trying to retrieve a page I have
legitimate access to, just doing it automatically when certain
conditions are met.)
Is that HTTP-auth? Then this might help:

http://www.voidspace.org.uk/python/a...tication.shtml

BTW, use urllib2.

Diez
Oct 14 '07 #2
On Oct 13, 11:41 pm, rodrigo <rodrigo...@gma il.comwrote:
I am trying to retrieve a password protected page using:

get = urllib.urlopen( 'http://password.protec ted.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 automatically?

(This is not a cracking attempt, I am trying to retrieve a page I have
legitimate access to, just doing it automatically when certain
conditions are met.)

Thanks,

Rodrigo
The pexpect module works nicely for automating tasks that normally
require user interaction.

Oct 14 '07 #3
On Behalf Of rodrigo
I am trying to retrieve a password protected page using:

get = urllib.urlopen( 'http://password.protec ted.url"').read ()
I would suggest looking at mechanize.
http://wwwsearch.sourceforge.net/mechanize/

from mechanize import Browser

USERNAME = "user"
PASSWORD = "secret"
LOGIN_PAGE = "http://password.protec ted.url/"

browser = Browser()
browser.open( LOGIN_PAGE )

# log in
browser.select_ form( nr=0 ) # Assuming log in form is first form on the page
# Check the form for the actual field names...
browser['user'] = USERNAME
browser['pass'] = PASSWORD
browser.submit( )

# Content goodness follows...

##
Of course, this assumes that the site doesn't use some kind of JavaScript
trickery to prevent automation like the above. In that case, you'd have to
use something like PAMIE
http://sourceforge.net/projects/pamie/

HTH,
Ryan Ginstrom

Oct 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4023
by: MCollins | last post by:
hi all, python newbie alert! i'm trying to open an array of websites, timing each site's response time (how may seconds until a response) if someone could point me in the right direction on accomplishing the timer part of the this application, i'd appreciate it. thanks in advance
2
2157
by: Ashutosh | last post by:
Our company has an intranet paging website. It gets all the contact and group addresses from SQL Server database. The paging is done through WCTP. It works properly except for only one group where it asks for username and passord when the user tries to send a page and does it successfully. But before I view the status of the page it asks me for username and password. It asks thrice and then give me an error web page. Any help would be...
1
10447
by: siddharth_jain_1 | last post by:
Hello I am trying to get a list of shared files and subdirectories in a particular folder on a server. For this I am using DirectoryInfo in the following way. DirectoryInfo folder = new DirectoryInfo("\\\\server_name\\shared_folder_name"); FileInfo fiArr = folder.GetFiles();
4
2336
by: kvicky | last post by:
I am trying to set a scheduled task for one of my ASP.net application that I developed on a monthly basis. This application requires a login authentication. I am sending the url of the login page in the Windows scheduled task. But I also want to send the username and password as Parameters (that is identified through windows authentication). and automatically assigned these parameters to loging into the application and conduct my...
3
1452
by: patelxxx | last post by:
Guy's, I'm using the following code and before I even enter my username and password I get the following error: 'Username or password did not match', what I'm I doing wrong? my $session = VM::Generic->new(); my $input = $session->parse_input; my $templateprefix = $input->{'area'} || 'reporting'; $session->validate_session($input);
8
3786
by: BJByrne | last post by:
Hi there, I want to open a database from a macro in another database and I have it working, except that we have usernames and passwords to log on, so when the macro is run is automatically asks for a username and password. I've tried entering the conditions as follows: 'Open the External Database in Access Window appAccess.OpenCurrentDatabase strDBPath, False, bstrPassword providing it with the database path (as String), that I...
1
3822
by: RAldridge | last post by:
Hi, I am a complete newb and experimenting with the VB code below. When I run this, the device on my intranet waits for username and password until it processes the resource. It there a way to pass the username and password in the code so I can automate the url? If I can automate it, then I can take out the .visible. Thanks so much. Option Explicit Dim objIEA Set objIEA = CreateObject("InternetExplorer.Application") objIEA.Navigate...
0
1008
by: vamsirays | last post by:
plz give me queries to find out username and password for sql server, if sql server have default username and password , then what is the username and password? thanking you krishna
0
8114
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8615
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8422
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6081
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4047
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4110
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1699
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.