Too much 404...

This commit is contained in:
Yohann D'ANELLO 2020-10-03 15:51:25 +02:00
parent aa51a40cf6
commit dcba832549
1 changed files with 6 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import json
import os
import re
import unicodedata
from urllib.error import HTTPError
import urllib.request
from django.db.models import QuerySet
@ -95,8 +96,11 @@ class MediaAdminForm(ModelForm):
api_url = "https://api2.isbndb.com/book/" + str(isbn) + "?Authorization=" + os.getenv("ISBNDB_KEY")
req = urllib.request.Request(api_url)
req.add_header("Authorization", os.getenv("ISBNDB_KEY"))
try:
with urllib.request.urlopen(req) as url:
data: dict = json.loads(url.read().decode())["book"]
except HTTPError:
return False
print(data)
data.setdefault("title", "")
data.setdefault("date_published", "1970-01-01")