Commit dcba8325 authored by ynerant's avatar ynerant

Too much 404...

parent aa51a40c
Pipeline #4242 failed with stages
in 3 minutes and 49 seconds
......@@ -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"))
with urllib.request.urlopen(req) as url:
data: dict = json.loads(url.read().decode())["book"]
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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment