I can not find the working aiohttp
code in combination with the login page. The goal is simple: forms-based authentication with the username and password that I would like to use a cookie in subsequent aiohttp asynchronous fetch calls.
It seems that the whole concept of Session has changed in aiohttp between versions, so I'm curious how I can implement it in the latest version. I am not sure how to get a cookie once and then use it in asynchronous matter.
I would really like to see a fully working example , because, unfortunately, I could not get it to work with all the fragments that I found everywhere.
I think this may be the beginning, but I'm not sure, and of course I do not see how I can connect everything to it (do I also need aiohttp.TCPConnector
?) Http://aiohttp.readthedocs.org/en/latest /client_reference.html#aiohttp.client.ClientSession
An example of my non-asynchronous version in Python 2 using mechanization (although I naturally use Python 3 for asyncio, etc.):
import mechanize import urllib class MyClass() def __init__(self): self.data = {'username' : 'me', 'password' : 'pw'} self.login_url = 'http://example.com/login' self.login() def call(self, url): request2 = mechanize.Request(url) self.cookie_jar.add_cookie_header(request2) response2 = mechanize.urlopen(request2).read() return response2 def login(self): request = mechanize.Request(self.login_url)
source share