wrapper.py 文件源码

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

项目:aiopixiv 作者: SunDwarf 项目源码 文件源码
def download_pixiv_image(self, image_url: str) -> bytes:
        """
        Downloads an image from Pixiv.

        Pixiv disables hotlinking or downloading the images directly without a Referer [sic] header with the correct
        location. This method automatically provides it.

        :param image_url: The image URL to get.
        :return: The bytes of the image.
        """
        headers = {
            "Referer": "http://spapi.pixiv.net/",
            "User-Agent": 'PixivIOSApp/6.0.9 (iOS 9.3.3; iPhone8,1)'
        }
        async with self.sess.get(image_url, headers=headers) as r:
            assert isinstance(r, aiohttp.ClientResponse)
            if r.status != 200:
                raise PixivError("Failed to download image {}".format(image_url))

            return await r.read()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号