DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Get A Jaiku Personal_key Given A Username And Password

  • submit to reddit
        Logs into Jaiku and then gets the personal_key for using the API.

def GetJaikuPersonalKey(user, password):
  """Finds the Jaiku API personal_key from a username and password.

  One day I'll learn to use urllib2 properly and cookie parsing and stuff.

  # login and find a cookie
  login_url = ""
  request_body = urllib.urlencode({'log': user,
                                   'pwd': password,
                                   'rememberme': '1'})
  # Open a connection to the authentication server.
  auth_connection = httplib.HTTPConnection('')
  # Begin the POST request to the client login service.
  auth_connection.putrequest('POST', '/login')
  # Set the required headers for an Account Authentication request.
  auth_connection.putheader('Content-Length', str(len(request_body)))
  auth_response = auth_connection.getresponse()
  if auth_response.status == 303:
    cookie_str = auth_response.getheader("set-cookie")
    # TODO(ark) parse this properly!
    res ="(jaikuuser_[^;]*).*(jaikupass_[^;]*)", cookie_str)
    if res:
      auth_cookie = "%s; %s" % (,
      apikey_url = ""
      req = urllib2.Request(url=apikey_url)
      req.add_header('Cookie', auth_cookie)
      f = urllib2.urlopen(req)