Login to Drupal 6 site using pycurl

David david at abbottdavid.com
Sun Apr 12 21:56:34 EDT 2009


I can not get this to work;

#!/usr/bin/python
import urllib
import pycurl

user_agent = 'Mozilla/4.0 (compatible: MSIE 6.0)'
crl = pycurl.Curl()
crl.setopt(pycurl.URL, 'http://beta.gentooligans.com')
crl.setopt(pycurl.HEADER, 1)
crl.setopt(pycurl.USERAGENT, user_agent)
crl.setopt(pycurl.FOLLOWLOCATION, 1)
crl.setopt(pycurl.COOKIEFILE, '/tmp/cookie.txt')
crl.setopt(pycurl.COOKIEJAR, '/tmp/cookie.txt')
login = [('name', 'username'),
         ('pass', 'password'),
         ('form-id', 'user_login'),
         ('op', 'Log in')]
login_data = urllib.urlencode(login)
crl.setopt(pycurl.POSTFIELDS, login_data)
crl.setopt(pycurl.URL, 'http://beta.gentooligans.com/user/login')
crl.perform()
crl.close()

I tried it like this also;

('edit[name]', user),
('edit[pass]', password),


output

[snip]

   <body class="not-logged-in not-front layout-first-main 
preface-first-middle-last postscript-first-middle-last">
     <div id="navigation"><div id="user-bar"><form 
action="/user/login?destination=user%2Flogin"  accept-charset="UTF-8" 
method="post" id="user-login-form">
<div><div class="form-item" id="edit-name-1-wrapper">
  <label for="edit-name-1">Username: <span class="form-required" 
title="This field is required.">*</span></label>
  <input type="text" maxlength="60" name="name" id="edit-name-1" 
size="15" value="" class="form-text required" />
</div>
<div class="form-item" id="edit-pass-1-wrapper">
  <label for="edit-pass-1">Password: <span class="form-required" 
title="This field is required.">*</span></label>
  <input type="password" name="pass" id="edit-pass-1"  maxlength="60" 
size="15"  class="form-text required" />
</div>
<input type="submit" name="op" id="edit-submit-2" value="Log in" 
class="form-submit" />

[snip]

Here are some guides I used;
http://code.activestate.com/recipes/267255/
http://drupal.org/node/87711

thanks,
-david

-- 
Powered by Gentoo GNU/Linux
http://linuxcrazy.com



More information about the Python-list mailing list