onepiece-tcg-notion-importer/onepiece_tcg/download.py

21 lines
518 B
Python

import json
from urllib.request import urlopen, Request
from urllib.error import URLError
def get_dict_from_url_response_body(url: str) -> str:
try:
request = Request(
url,
headers={
"User-Agent": "onepiece-tcg-notion-importer",
},
)
with urlopen(request) as response:
data = response.read()
return json.loads(data)
except URLError as e:
raise e
except json.JSONDecodeError as e:
raise e