473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Question about urllib and posting to an external script

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='multipart/form-data' action='http://login.myspace.com/index.cfm?fuseaction=login.process&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 3171
lself
1
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='multipart/form-data' action='http://login.myspace.com/index.cfm?fuseaction=login.process&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 Expert 4TB
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
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 ... ...
3
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...
7
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...
1
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...
1
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...
1
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...
5
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...
5
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...
5
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...
4
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.