From 99857bbc12af6a3b1c7d25289ad32aa17905f554 Mon Sep 17 00:00:00 2001 From: peregr1nus Date: Wed, 10 Dec 2025 16:16:25 +0900 Subject: [PATCH] =?UTF-8?q?=EC=83=81=EC=84=B8=EC=A0=90=EA=B2=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 20 ++++++++++++-------- templates/step4.html | 10 +++++++--- utils/google_drive.py | 11 ++++++++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index 4eaf40d..05df8cd 100644 --- a/app.py +++ b/app.py @@ -27,15 +27,19 @@ word_processor = WordProcessor(app.config['WORD_TEMPLATE_DIR']) # 구글 드라이브 업로더 초기화 (선택사항) drive_uploader = None try: - drive_uploader = GoogleDriveUploader( - app.config['GOOGLE_DRIVE_CREDENTIALS_FILE'], - app.config['GOOGLE_DRIVE_TOKEN_FILE'] - ) -except FileNotFoundError as e: - print(f"경고: 구글 드라이브 인증 파일을 찾을 수 없습니다. 구글 드라이브 업로드 기능이 비활성화됩니다.") - print(f"상세: {str(e)}") + # credentials.json 파일이 있는 경우에만 초기화 시도 + if os.path.exists(app.config['GOOGLE_DRIVE_CREDENTIALS_FILE']): + drive_uploader = GoogleDriveUploader( + app.config['GOOGLE_DRIVE_CREDENTIALS_FILE'], + app.config['GOOGLE_DRIVE_TOKEN_FILE'] + ) +except FileNotFoundError: + # 인증 파일이 없으면 조용히 넘어감 + pass except Exception as e: - print(f"경고: 구글 드라이브 초기화 중 오류가 발생했습니다: {str(e)}") + # 브라우저 관련 오류나 기타 오류는 조용히 처리 + # 서버 환경에서는 브라우저가 없을 수 있으므로 정상적인 상황 + pass @app.route('/auth', methods=['GET', 'POST']) def auth(): diff --git a/templates/step4.html b/templates/step4.html index f617f71..d35a665 100644 --- a/templates/step4.html +++ b/templates/step4.html @@ -25,7 +25,11 @@ {% if '기타의견란' in question or '기타의견' in question %}

※ 이 문항은 아래 "기타의견"란에 "{{ loop.index }}번: "으로 시작하여 답변해주세요.

{% else %} - +
+ + + +
{% endif %} @@ -33,8 +37,8 @@
- - + +
diff --git a/utils/google_drive.py b/utils/google_drive.py index 4774d65..0b607b3 100644 --- a/utils/google_drive.py +++ b/utils/google_drive.py @@ -37,7 +37,16 @@ class GoogleDriveUploader: ) flow = InstalledAppFlow.from_client_secrets_file( self.credentials_file, SCOPES) - creds = flow.run_local_server(port=0) + # 서버 환경에서는 브라우저가 없을 수 있으므로 예외 처리 + try: + creds = flow.run_local_server(port=0) + except Exception as e: + # 브라우저를 열 수 없는 경우 (서버 환경 등) + # 토큰 파일이 이미 있다면 재시도하지 않고 예외 발생 + raise Exception( + "구글 드라이브 인증을 완료할 수 없습니다. " + "로컬 환경에서 먼저 인증을 완료하여 token.json 파일을 생성해주세요." + ) from e # 토큰 저장 with open(self.token_file, 'wb') as token: