aiohttp.ClientSession 似乎没有 post 我提供的数据(用户名、密码、logintoken)

aiohttp.ClientSession doesn't seem to post the data (username, password, logintoken) that I give it

我一直在尝试将我的一个程序转为异步,但会话似乎没有 post 数据。

from aiohttp import ClientSession as Session
from bs4 import BeautifulSoup as BS
import asyncio

class Finder(Session):
    async def login(self, loginurl, homeurl, username, password):
        async def getlogintoken(loginurl):
            async with self.get(loginurl) as loginpage:
                return(BS(await loginpage.text(), 'html.parser').select('#login > input[type=hidden]:nth-child(3)')[0]['value'])

        async def postlogindata(loginurl, username, password, logintoken):
            await self.post(loginurl, data={'username': username, 'password': password, 'logintoken': logintoken})

        async def gethome(homeurl):
            async with self.get(homeurl) as homepage:
                print(homepage.url)

        logintoken = await getlogintoken(loginurl)
        print(logintoken)
        await postlogindata(loginurl, username, password, logintoken)
        await gethome(homeurl)

这就是我所拥有的,它可以很好地处理请求(没有所有异步内容),但是对于 aiohttp 它似乎不起作用。 任何帮助将不胜感激!

我弄清楚出了什么问题: ClientSession 不会自动保存 cookie。它发布正确,但为了保留会话 ID,您必须在获取登录令牌时更新 cookie。

async with self.get(loginurl) as loginpage:
            self.cookie_jar.update_cookies(loginpage.cookies)
            return BS(await loginpage.text(), 'html.parser').find(attrs={'name': 'token'})['value']