import urllib
import urllib2
import cookielib
page_address="http://www.*****.com/login.html"
cookie_handler = urllib2.HTTPCookieProcessor(cookielib.CookieJar())
redirect_handler = urllib2.HTTPRedirectHandler()
http_handler = urllib2.HTTPHandler()
https_handler = urllib2.HTTPSHandler()
# Загружаем хэндлеры в opener
opener = urllib2.build_opener(http_handler, https_handler, cookie_handler, redirect_handler)
# подключаем прокси
proxy_handler = urllib2.ProxyHandler(proxies)
opener.add_handler(proxy_handler)
# Устанавливаем заголовок User-agent
opener.addheaders = [('User-agent', useragent)]
urllib2.install_opener(opener)
params = urllib.urlencode({'user':login,'pass':password,'backfromssl':0,'refer':''})
request = urllib2.Request(page_address, params)
f = urllib2.urlopen(request)
cookie = unicode(f.headers['Set-Cookie'], 'cp1251')
# получаем значение cookie (например, id сессии):
matches = re.findall('(?si)SID=(.*?);', cookie)
cookie = matches[0]
print cookie
File “C:\Python26\lib\rfc822.py”, line 388, in __getitem__
return self.dict
KeyError: ‘set-cookie’