diff --git a/backend/app/api/carmodoo.py b/backend/app/api/carmodoo.py index c883772..f171c01 100644 --- a/backend/app/api/carmodoo.py +++ b/backend/app/api/carmodoo.py @@ -96,24 +96,15 @@ class CarmodooClient: } def _decode_response(self, content: bytes) -> str: - """EUC-KR 응답 디코딩""" - try: - return content.decode('euc-kr') - except UnicodeDecodeError: - try: - return content.decode('utf-8') - except UnicodeDecodeError: - return content.decode('latin-1') + """EUC-KR 응답 디코딩 - 유효하지 않은 바이트는 대체문자로 처리""" + # errors='replace'를 사용하여 유효하지 않은 바이트 시퀀스를 대체문자(�)로 처리 + # 이렇게 하면 일부 특수문자가 깨지더라도 한글 텍스트는 보존됨 + return content.decode('euc-kr', errors='replace') def _clean_xml_bytes(self, content: bytes) -> bytes: """XML 정리""" - try: - text = content.decode('euc-kr') - except UnicodeDecodeError: - try: - text = content.decode('utf-8') - except UnicodeDecodeError: - text = content.decode('latin-1') + # errors='replace'를 사용하여 유효하지 않은 바이트 시퀀스 처리 + text = content.decode('euc-kr', errors='replace') text = re.sub(r'^[0-9a-fA-F]+\r?\n', '', text, flags=re.MULTILINE) text = text.strip()