편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2020.11.30

    파이썬 decoding 질문입니다. UnicodeDecodeError 'utf-8' codec can't decode byte 0xb5 in position 3


    파이썬으로 쉘을 만들고있습니다.

    import os
    from subprocess import check_output
    print(check_output("dir", shell=True).decode('utf-8'))
    

    이런식으로 subprocess모듈을 사용하여 cmd명령어를 입력하면 반환되는 값을 return받아 print하는 프로그램인데요.

    반환값이 영어만 존재하는 명령어를 입력할 경우 잘 작동하지만, 한글이 섞여있는 명령 즉 예를들면 dir명령같은것을 사용했을 경우에는 UnicodeDecodeError가 발생합니다.

    에러명은 아래와 같구요 'utf-8' codec can't decode byte 0xb5 in position 3: invalid start byte

    이렇게 반환값이 byte, utf-8이 같이섞여있는경우 어떤식으로 디코딩을 해주어야하나요 ㅠㅠ

  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.01.01

    파이썬 decoding 질문입니다.


    파이썬으로 쉘을 만들고있습니다.

    import os
    from subprocess import check_output
    print(check_output("dir", shell=True).decode('utf-8'))
    

    이런식으로 subprocess모듈을 사용하여 cmd명령어를 입력하면 반환되는 값을 return받아 print하는 프로그램인데요.

    반환값이 영어만 존재하는 명령어를 입력할 경우 잘 작동하지만, 한글이 섞여있는 명령 즉 예를들면 dir명령같은것을 사용했을 경우에는 UnicodeDecodeError가 발생합니다.

    에러명은 아래와 같구요 'utf-8' codec can't decode byte 0xb5 in position 3: invalid start byte

    이렇게 반환값이 byte, utf-8이 같이섞여있는경우 어떤식으로 디코딩을 해주어야하나요 ㅠㅠ