From 570875f4b120d15e44440a75ae353d152365b8f3 Mon Sep 17 00:00:00 2001 From: bhvishal Date: Tue, 20 Aug 2024 11:28:11 +0200 Subject: [PATCH] Debug commit --- .env.example | 4 +--- docker-compose.yml | 4 +--- vectorizing/__init__.py | 1 + vectorizing/server/s3.py | 6 +++--- vectorizing/util/read.py | 13 +++++++++---- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 30b50c1..e7f0514 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,3 @@ PORT="8000" -AWS_ACCESS_KEY_ID="AWS_ACCESS_KEY_ID" -AWS_SECRET_ACCESS_KEY="AWS_SECRET_ACCESS_KEY" S3_BUCKET="S3_BUCKET" -S3_TEST_BUCKET="S3_TEST_BUCKET" \ No newline at end of file +S3_TEST_BUCKET="S3_TEST_BUCKET" diff --git a/docker-compose.yml b/docker-compose.yml index 65c7e94..aa4c1e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,6 @@ x-build: &build x-env: &env environment: - PORT=${PORT} - - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} - - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} - S3_BUCKET=${S3_BUCKET} - S3_TEST_BUCKET=${S3_TEST_BUCKET} - SENTRY_DSN=${SENTRY_DSN} @@ -19,4 +17,4 @@ services: <<: [*build, *env] command: gunicorn -w 4 'vectorizing:create_app()' --timeout 0 -b 0.0.0.0:$PORT --log-level debug ports: - - ${PORT}:${PORT} \ No newline at end of file + - ${PORT}:${PORT} diff --git a/vectorizing/__init__.py b/vectorizing/__init__.py index 8079cd4..14eaf17 100644 --- a/vectorizing/__init__.py +++ b/vectorizing/__init__.py @@ -92,6 +92,7 @@ def index(): timer = Timer() timer.start_timer('Image Reading') + print(url) img = try_read_image_from_url(url) timer.end_timer() diff --git a/vectorizing/server/s3.py b/vectorizing/server/s3.py index a002585..34e9c67 100644 --- a/vectorizing/server/s3.py +++ b/vectorizing/server/s3.py @@ -1,7 +1,7 @@ import cuid import boto3 -S3 = boto3.client("s3") +S3 = boto3.client('s3') def upload_markup (markup, s3_bucket_name): cuid_str = cuid.cuid() @@ -21,7 +21,7 @@ def get_object_url(s3_file_key, s3_bucket_name): Key=s3_file_key, Bucket=s3_bucket_name ) - + except(Exception): return None @@ -40,4 +40,4 @@ def upload_file( s3_bucket_name, s3_file_key, ) - return get_object_url(s3_file_key, s3_bucket_name) \ No newline at end of file + return get_object_url(s3_file_key, s3_bucket_name) diff --git a/vectorizing/util/read.py b/vectorizing/util/read.py index 54edea1..8c434fa 100644 --- a/vectorizing/util/read.py +++ b/vectorizing/util/read.py @@ -23,7 +23,7 @@ def __init__(self): def convert_RGB_A(img): if img.mode == 'RGB' or img.mode == 'RGBA': return img - + map = { '1': 'RGB', 'L': 'RGB', @@ -33,7 +33,7 @@ def convert_RGB_A(img): if not img.mode in map: raise ImageFormatError() - + return img.convert(map.get(img.mode)) def try_read_image_from_path(path): @@ -46,7 +46,12 @@ def try_read_image_from_path(path): def try_read_image_from_url(url): try: resp = requests.get(url, headers={"User-Agent": "KittlVectorizing/1.0.0"}) + resp.raise_for_status() # Raise an HTTPError for bad responses (e.g., 403, 404) img = Image.open(BytesIO(resp.content)) - except: + except requests.exceptions.RequestException as e: + print(f"HTTP error occurred: {e}") # Detailed error message raise URLReadError() - return convert_RGB_A(img) \ No newline at end of file + except Exception as e: + print(f"Image processing error: {e}") # Detailed error message + raise URLReadError() + return convert_RGB_A(img)