V
V
Vitaly Ananiev2021-07-08 21:55:09
Python
Vitaly Ananiev, 2021-07-08 21:55:09

ModuleNotFoundError: No module named 'PIL' what is the problem?

import requests
from PIL import Image
from io import BytesIO

def download(query: str, page_count: int) -> None:
header = {"Authorization": "563492ad6f9170000100000145dbaba8c0d74b6a95b6158a5e954c06"}
params = {"query": query, "per_page": 1 }
url = f" https://api.pexels.com/v1/search "
i = 1
while i <= page_count:
params["page"] = i
r = requests.get(url, headers=header, params= params)
if r.status_code == 200:
_r = r.json()
for item in _r.get("photos"):
_img_url = item.get("src").get("original")
resp = requests.get(_img_url)

print(_img_url)

image = Image.open(BytesIO(resp.content))
image.save(f"media/{query}_{i}.{_img_url.split('.'[ -1])}")
else:
print(r.text)
i += 1

def main() -> None:
query = input("Query ")
page_count = int(input("Count page "))
download(query , page_count)

main()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question