Я делаю Python скрипт, который выбирает магазин предметов Fortnite из API, сохраняет всю необходимую информацию и затем выводит на экран изображение предмета в магазине, но я получаю ValueError: images не соответствовать. Все изображения имеют одинаковое разрешение и все в формате PNG, но документация PIL мне мало что объясняет.
# Importing JSON handling library for parsing GET request using requests library
import json
import requests
from PIL import Image
from io import BytesIO
# Creating blank lists & variables for later use
featured_list = []
daily_list = []
inc = 0
# API Endpoint
url = "https://fnbr.co/api/shop"
# API key
key = "ee9f93b4-2a91-4681-96b7-3f9485c9b14c" # key is usually here
# Defining Parameters
headers = {"x-api-key":key}
# Sending GET request
req = requests.get(url = url, headers = headers)
# Converting request data into JSON format
info = req.json()
# Finds appropriate pieces of data for Featured Item Shop
info = info['data']['featured']
for x in info:
featured_name = x['name']
featured_rarity = x['rarity']
featured_icon_url = x['images']['icon']
print(featured_name, featured_rarity, featured_icon_url)
if featured_rarity == "marvel":
imgpath = "/home/pi/Desktop/Item Shop/Rarity/Marvel.png"
bg = Image.open(imgpath)
response = requests.get(featured_icon_url)
f_icon = Image.open(BytesIO(response.content))
final1 = Image.new("RGBA", bg.size)
final1 = Image.alpha_composite(final1, bg)
final1 = Image.alpha_composite(final1, f_icon)
final1.save("final{}.png".format(inc))
inc += 1
else:
break
# Converts request data into JSON format again to access Daily Item Shop
info = req.json()
# Finds appropriate pieces of data for Daily Item Shop
info = info['data']['daily']
for y in info:
daily_name = y['name']
daily_rarity = y['rarity']
daily_icon_url = y['images']['icon']
print(daily_name, daily_rarity, daily_icon_url)
Ошибка, которую я получаю:
Traceback (most recent call last):
File "/home/pi/Desktop/Item Shop/bot.py", line 45, in <module>
final1 = Image.alpha_composite(final1, f_icon)
File "/home/pi/.local/lib/python3.8/site-packages/PIL/Image.py", line 2837, in alpha_composite
return im1._new(core.alpha_composite(im1.im, im2.im))
ValueError: images do not match
Любая помощь оценили!