*/

Python - Type Error

Python에서 아래와 같은 오류가 발생할 경우

A Bytes-Like Object Is Required, Not ‘Str'

  bytes-likes 오브젝트가 필요하니 str 타입 말고 bytes 타입의 변수를 넣으라는 의미로 라이브러리등을 사용하다 보면 주로 발생하고 string type 과  bytes 타입은 아래와 같은 상관 관계가 있다.

str –> 디코딩 –> bytes

bytes –> 인코딩 –> str

text = "Hello"    
text_byte = text.encode('utf-8')
text_str = text_byte.decode('utf-8')
text_byte = "Hello".encode('utf-8')


참고


0 comments:

댓글 쓰기