web.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:Pyanimelist 作者: GetRektByMe 项目源码 文件源码
def fetch_url(url: str, auth: aiohttp.BasicAuth, headers: Dict["str", "str"] = None):
    """
    Function used to eliminate code reuse with creating ClientSessions

    :param str url: The URL you're fetching
    :param aiohttp.BasicAuth auth: The BasicAuth object being passed to aiohttp.ClientSession
    :param dict headers: The headers to be passed to `myanimelist`_

    :rtype: bytes

    Example usage:

    .. code-block:: py

       import asyncio

       loop = asyncio.get_event_loop()
       loop.run_until_complete(fetch_url("url", aiohttp.BasicAuth(login="username", password="password"), {"User-Agent": "PyAnimeList"}))
    """
    if not headers:
        headers = {}
    with aiohttp.ClientSession(auth=auth, headers=headers) as session:
        async with session.get(url) as response:
            return response.read()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号