webcap.py 文件源码

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

项目:plumeria 作者: sk89q 项目源码 文件源码
def render(url, width=1024, max_height=4096, trim_image=False):
    with DefaultClientSession(connector=TCPConnector()) as session:
        async with session.request(method="post", url=render_url(), data=json.dumps({
            "url": url,
            "key": api_key(),
            "width": str(width),
            "max_height": str(max_height),
            "trim": "true" if trim_image else "false",
        })) as r:
            if r.status == 200:
                buffer = io.BytesIO()
                buffer.write(await r.read())
                return Response("", attachments=[MemoryAttachment(buffer, "screenshot.jpg", "image/jpeg")])
            else:
                try:
                    data = await r.json()
                    raise CommandError("error occurred: {}".format(data['error']))
                except JSONDecodeError:
                    raise CommandError("error occurred with status code {}".format(r.status))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号