This one logs me into pop.org

import urllib
import cookielib

class dummy_request:
    def get_full_url(self):
        return '/'

def extract_cookies(response):
    """Given a response, returns a dictionary of the cookies."""
    ns_headers = response.headers.getheaders("Set-Cookie")
    attrs_set = cookielib.parse_ns_headers(ns_headers)
    cookie_tuples = cookielib.CookieJar()._normalized_cookie_tuples(attrs_set)
    cookies = {}
    for tup in cookie_tuples:
        name, value, standard, rest = tup
        cookies[name] = value
    return cookies
    
def log_into_pop(username, password):
    url = 'http://www.peopleofpraise.org/user/login'
    args = {'edit[name]': username, 'edit[pass]': password}
    response = urllib.urlopen(url, urllib.urlencode(args))
    return extract_cookies(response)

if __name__ == '__main__':
    import getpass
    username = 'Collin Anderson'
    password = getpass.getpass()
    print log_into_pop(username, password)
Advertisements