Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 1st, 2004, 08:06 PM
pashaweb pashaweb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 pashaweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Python - easy question

Hello, I'm pretty new to Python and have the following question before I proceed with studying it further:

The question is about openurl function.

Let's say I want my python script to access password protected page, how would I do that?

Will it open IE and try to access it or does it access the page "internally".

Sample code would be awesome.

Reply With Quote
  #2  
Old March 2nd, 2004, 05:23 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,532 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 38 m 15 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Hi Pasha,

This rather untidy example used to work fine but with the recent update to Devsheds forums it could very well be broken

Code:
#!/usr/bin/env python

import urllib, urllib2

def update(link, username, password, email, signature):
	
	param1 = urllib.urlencode({'action': 'login', 'username': username, 'password': password}) 
	param2 = urllib.urlencode({'action': 'updateprofile', 'email': email, 'emailconfirm': email, 'signature': signature}) 
 
	cookie = urllib.urlopen(link, param1).info()['Set-Cookie'] 
	cookie = [c for c in cookie.split() if c.endswith(';')][::2]
 
	urllib.urlopen(urllib2.Request(link, param2, {'Cookie': ''.join(cookie)}))
	
update('http://forums.devshed.com/member.php', 'netytan', 'passwd', 'netytan@somewhere.com', 'www.python.org')


If you hadn't guessed it already, this script updates a users signature. But it does show how you can pass arguments to pages etc.

Not for the weak heated and it usually takes some time to figure out jsut what a page needs. especially if you can't look at the source code!

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old March 2nd, 2004, 10:24 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
I used this in a batch file:
Code:
import urllib
class myopener(urllib.FancyURLopener):
    def prompt_user_passwd(self,host,realm):
        return ("username","password")
    
sess = myopener()

f = sess.open("http://somewhere/index.html")
page = f.read()

just put in a valid username and password. You can of course modify prompt_user_passwd to use raw_input

Grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python - easy question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway