473,569 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about urllib and posting to an external script

3 New Member
I have tried multiple ways of posting information to a website and have failed.

my first attempt was out of the docs:

Expand|Select|Wrap|Line Numbers
  1. import httplib, urllib
  2. params = urllib.urlencode({'email' : 'a@a.com', 'password' : 'pass'})
  3. h = httplib.HTTP("login.myspace.com:80")
  4. h.putrequest("POST", "/index.cfm?fuseaction=login.process&amp")
  5. h.putheader("User-Agent", "Mozilla/5.0 <Windows; U; Windows NT 5.1; en-US; rv;1.8.0.6> Gecko/20060728 Firefox/1.5.0.6")
  6. h.putheader("Content-length", "%d" % len(params))
  7. h.putheader('Accept', 'text/plain')
  8.  
  9. h.endheaders()
  10. h.send(params)
  11. reply, msg, hdrs = h.getreply()
  12. print reply # should be 200
  13. data = h.getfile().read() # get the raw HTML
  14. print data 
this returned a page denying access
and then tried:

Expand|Select|Wrap|Line Numbers
  1. import httplib, urllib
  2. params = urllib.urlencode({'email' : 'ezikz@bonbon.net', 'password' : 'dicksuck'})
  3. data = urllib.urlopen("http://login.myspace.com/index.cfm?fuseaction=login.process&amp:80", params).read() 
  4. print data 
This returned a page that asked me if i wanted to sign up, which confused me even more.

all i want to do is post this form:
[HTML]<form method='POST' enctype='multip art/form-data' action='http://login.myspace.c om/index.cfm?fusea ction=login.pro cess&amp'>
<input type="text" name="email" >
<input type="password" name="password" >
<input type="submit" value="Login"/>[/HTML]

Please help i was thinking maybe the site did browser sniffing and only allowed certain types. i dont know.
Sep 4 '06 #1
2 3183
lself
1 New Member
Get ClientCookie from http://wwwsearch.sourceforge.net/ClientCookie/

Inside the ClientCookie-x.x.x directory, you will find a directory called ClientCookie. Copy it to C:\Python2x\Lib \site-packages.

Change youremail, yourpassword, and anyfriendid in the following code:

Expand|Select|Wrap|Line Numbers
  1. import urllib
  2. import urllib2
  3. import ClientCookie
  4.  
  5. params = urllib.urlencode({'email':'youremail','password':'yourpassword'})
  6. request = urllib2.Request("http://login.myspace.com/index.cfm?fuseaction=login.process&amp",params)
  7. response = urllib2.urlopen(request)
  8. c = ClientCookie.Cookies()
  9. c.extract_cookies(response,request)
  10. request2 = urllib2.Request("http://comment.myspace.com/index.cfm?fuseaction=user.viewComments&friendID=anyfriendid")
  11. c.add_cookie_header(request2)
  12. url2 = urllib2.urlopen(request2)
This loads (as an example) the View All Comments page of the user with anyfriendid--something you must be logged in to do. If you wish to do something else, it should be easy to infer how.

I have tried multiple ways of posting information to a website and have failed.

my first attempt was out of the docs:

Expand|Select|Wrap|Line Numbers
  1. import httplib, urllib
  2. params = urllib.urlencode({'email' : 'a@a.com', 'password' : 'pass'})
  3. h = httplib.HTTP("login.myspace.com:80")
  4. h.putrequest("POST", "/index.cfm?fuseaction=login.process&amp")
  5. h.putheader("User-Agent", "Mozilla/5.0 <Windows; U; Windows NT 5.1; en-US; rv;1.8.0.6> Gecko/20060728 Firefox/1.5.0.6")
  6. h.putheader("Content-length", "%d" % len(params))
  7. h.putheader('Accept', 'text/plain')
  8.  
  9. h.endheaders()
  10. h.send(params)
  11. reply, msg, hdrs = h.getreply()
  12. print reply # should be 200
  13. data = h.getfile().read() # get the raw HTML
  14. print data 
this returned a page denying access
and then tried:

Expand|Select|Wrap|Line Numbers
  1. import httplib, urllib
  2. params = urllib.urlencode({'email' : 'ezikz@bonbon.net', 'password' : 'dicksuck'})
  3. data = urllib.urlopen("http://login.myspace.com/index.cfm?fuseaction=login.process&amp:80", params).read() 
  4. print data 
This returned a page that asked me if i wanted to sign up, which confused me even more.

all i want to do is post this form:
[HTML]<form method='POST' enctype='multip art/form-data' action='http://login.myspace.c om/index.cfm?fusea ction=login.pro cess&amp'>
<input type="text" name="email" >
<input type="password" name="password" >
<input type="submit" value="Login"/>[/HTML]

Please help i was thinking maybe the site did browser sniffing and only allowed certain types. i dont know.
Jan 7 '07 #2
bartonc
6,596 Recognized Expert Expert
Get ClientCookie from http://wwwsearch.sourceforge.net/ClientCookie/

Inside the ClientCookie-x.x.x directory, you will find a directory called ClientCookie. Copy it to C:\Python2x\Lib \site-packages.

Change youremail, yourpassword, and anyfriendid in the following code:

Expand|Select|Wrap|Line Numbers
  1. import urllib
  2. import urllib2
  3. import ClientCookie
  4.  
  5. params = urllib.urlencode({'email':'youremail','password':'yourpassword'})
  6. request = urllib2.Request("http://login.myspace.com/index.cfm?fuseaction=login.process&amp",params)
  7. response = urllib2.urlopen(request)
  8. c = ClientCookie.Cookies()
  9. c.extract_cookies(response,request)
  10. request2 = urllib2.Request("http://comment.myspace.com/index.cfm?fuseaction=user.viewComments&friendID=anyfriendid")
  11. c.add_cookie_header(request2)
  12. url2 = urllib2.urlopen(request2)
This loads (as an example) the View All Comments page of the user with anyfriendid--something you must be logged in to do. If you wish to do something else, it should be easy to infer how.
There is great info here for our members. Thank you for taking the time to post. I hope that you stick around, ask some, answer some, or just post some code that you are working on.
Jan 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3976
by: Richard Shea | last post by:
Hi - I'm new to Python. I've been trying to use URLLIB and the 'tidy' function (part of the mx.tidy package). There's one thing I'm having real difficulties understanding. When I did this ... finA= urllib.urlopen('http://www.python.org/') foutA=open('C:\\testout.html','w') tidy(finA,foutA,None) I get ...
3
2453
by: Haim Ashkenazi | last post by:
Hi I'm writing a script that uses urllib on win98. until now I used python 2.3.x (x < 4) and it worked ok. I re-installed windows and installed python 2.3.4 and now I get an error when trying to open a url "no host given": Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 Type "copyright", "credits" or "license()" for more...
7
2321
by: Stuart McGraw | last post by:
I just spent a $*#@!*&^&% hour registering at ^$#@#%^ Sourceforce and trying to submit a Python bug report but it still won't let me. I give up. Maybe someone who cares will see this post, or maybe it will save time for someone else who runs into this problem... ================================================ Environment: - Microsoft...
1
2487
by: John Hunter | last post by:
I have a test script below which I use to fetch urls into strings, either over https or http. When over https, I use m2crypto.urllib and when over http I use the standard urllib. Whenever, I import sockets and setdefaulttimeout, however, using m2crypto.urllib tends to cause a http.BadStatusLine to be raised, even if the timeout is set to be...
1
1688
by: Tigerhillside | last post by:
I forgot I had a "real" newsreader available. So here is the question you will see "soon" when google decides to post my other question. I have a server side script that takes a user's input in a form, packages it, and sends it on to an external server. The external server will then send back the response via http to my server script....
1
496
by: evanpmeth | last post by:
I have tried multiple ways of posting information to a website and have failed. I have seen this problem on other forums can someone explain or point me to information on how POST works through urllib an different broweser (what is the difference). my first attempt was out of the docs: Code: import httplib, urllib params =...
5
4661
by: supercooper | last post by:
I am downloading images using the script below. Sometimes it will go for 10 mins, sometimes 2 hours before timing out with the following error: Traceback (most recent call last): File "ftp_20070326_Downloads_cooperc_FetchLibreMapProjectDRGs.py", line 108, i n ? urllib.urlretrieve(fullurl, localfile) File "C:\Python24\lib\urllib.py", line...
5
1736
by: Adrian Smith | last post by:
I'm trying to use urllib2 to download a page (I'd rather use urllib, but I need to change the User-Agent header to look like a browser or G**gle won't send it to me, the big meanies). The following (pinched from Dive Into Python) seems to work perfectly in Idle, but falls at the final hurdle when run as a cgi script - can anyone suggest...
5
13029
by: chrispoliquin | last post by:
Hi, I have a small Python script to fetch some pages from the internet. There are a lot of pages and I am looping through them and then downloading the page using urlretrieve() in the urllib module. The problem is that after 110 pages or so the script sort of hangs and then I get the following traceback: Traceback (most recent call...
4
2900
by: K | last post by:
Hello everyone, I understand that urllib and urllib2 serve as really simple page request libraries. I was wondering if there is a library out there that can get the HTTP requests for a given page. Example: URL: http://www.google.com/test.html Something like: urllib.urlopen('http://www.google.com/
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
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
7974
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
6284
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
5513
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
5219
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
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1221
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.