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()
评论列表
文章目录