123456789101112131415161718192021222324 |
- from json.decoder import JSONDecodeError
- import requests
- from requests.exceptions import ConnectionError
- def upload_image(key, content):
- try:
- return True, requests.post(
- "https://api.imgur.com/3/image",
- headers={
- "Authorization": f"Client-ID {key}",
- },
- data=content
- ).json()["data"]["link"]
- except ConnectionError as ce:
- return False, {
- "explain": "Could not reach image service.",
- "exception": ce
- }
- except (KeyError, JSONDecodeError) as e:
- return False, {
- "explain": "Could not parse response from image service.",
- "exception": e
- }
|