Python
Python) Base64 Decoding 에러 처리 - Non-base64 digit found
로픽
2022. 5. 9. 16:55
300x250
Base64 Decoding 에러 처리 - Non-base64 digit found
base64 decoding 시 입력된 값이 base64 형식에 어긋나면 에러메시지(Non-base64 digit found) 를 반환.
( base64 형식 = [A-Za-z0-9+/]*={0,2} )
[참고]
Base64 형식에 어긋난 경우 에러 처리
- 정규표현식으로 입력된 체크 후 base64 형식 어긋난 경우 RuntimeError를 던짐
def base64_Decoding(incode_str):
base64_str = incode_str
if not re.fullmatch('[A-Za-z0-9+/]*={0,2}', base64_str):
raise RuntimeError
str_bytes = base64.b64decode(base64_str)
init_str = str_bytes.decode('utf-8')
return init_str
- RuntimeError를 받으면 Messagebox를 출력
def baseDecoding_clicked(self):
try:
decode_data = inDecoding.base64_Decoding(self.te2_af.toPlainText())
self.te2_be.setText(decode_data)
except RuntimeError:
QMessageBox.about(self, '경고', 'base64 형식이 아닙니다.')
반응형