python - 无法使用 pixivpy3 从 Pixiv 下载图像
问题描述
我正在尝试使用该pixivpy3
库从 Pixiv 下载图像。我能够进行身份验证并接收图像列表,但是在使用requests
下载图像时,我收到了 403。
pic = random.choice(AllPics)
PicID = pic['id']
PicURL = f"https://www.pixiv.net/en/artworks/{PicID}"
SavedPicPath = f'imgTmp/{PicID}_p0.jpg'
response = requests.get(PicURL,
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36',
'referer' : PicURL,
'scheme' : 'https',
'accept' : 'image/webp,image/apng,image/*,*/*;q=0.8'
},
stream=True)
if os.path.exists(SavedPicPath):
os.remove(SavedPicPath)
with open(SavedPicPath, 'wb') as Out_file:
Out_file.write(response.raw)
DiscordFileObject = File(SavedPicPath)
我收到的错误是
TypeError: a bytes-like object is required, not 'HTTPResponse'
,这是因为response
是 403 错误。我直接从 Chrome 复制了标题,所以我不确定为什么我仍然得到这个。我也认证了
解决方案
问题是我的网址不正确。正确的网址是pic['image_urls']['large']
推荐阅读
- c++ - 从结构类型中查找类型(可能是底层)以在模板中使用
- laravel-5 - Laravel 在雄辩的模型中禁用列
- python - 用 0 到 1 之间的值替换 numpy 数组元素
- c# - Db 的数据准备和验证应该在服务或存储库中的哪里完成?
- angular - mat-list-item 中的 mat-form-field 重叠
- php - 错误:警告:php 代码中遇到的非数字值
- elasticsearch - 在这个 java spring boot 应用程序中使用 logstash 时如何调用 filebeats?
- android - 如何将“onCreateViewHolder”中的代码迁移到“onBindViewHolder”
- sql - 无法在字符集之间音译字符
- expo - ActionBar上的Vue Native“元素类型无效:预期为字符串”