How can I achieve basic authentication in Drupal? I am trying to get working webservices in drupal (Services, restws,...), but ,as a first step I am trying to get a cookie using 'Basic Authorization' using the following python script:

import urllib2
import base64

def login(u,p):
    url = 'http://127.0.0.1/drupal/node?destination=node'
    r = urllib2.Request(url,None,{'Authorization':'Basic '+base64.b64encode(u +':' + p),
                                  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                              'Accept-Encoding': 'gzip, deflate'})
    f = urllib2.urlopen(r)
    cookie = f.headers.dict['set-cookie'] # &lt;--- this fails, raises exception
    csrf = f.read()
    return csrf,cookie


csrf, cookie= login('username', 'password')
print base64.b64encode(csrf)
print "cookie:", cookie


The line 'cookie=f.headers.dict['set-cookie']' fails, since there's no cookie returned in the response. 
What could I have  missed ?
Drupal 7 will not set a session cookie unless it has to, for performance reasons. If there is no form under http://127.0.0.1/drupal/node, and no module requires sessions, you will not get any session, simple as that.