구글 번역기를 무료로 사용할 수 있는 패키지인 googletrans 를 사용하다 보면 만날 수 있는 오류이다.
translator = Translator()
result = translator.translate(text, dest="ko")
googletrans를 검색하다 보면 볼 수 있는 기본 예제인데, text 변수에 길이가 긴 텍스트를 입력하면, json으로 받아들여지지 않는
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
오류를 만날 수 있다. 아래 깃헙 내용을 확인해보면, 공식 googletrans문서와는 다르게 번역시 5000자 내의 텍스트만 번역이 가능하다고 말하는 것을 보니, 그 이상으로 길면 제대로된 결과를 google 번역기가 제대로 반환을 안해주는 모양.
https://github.com/ssut/py-googletrans/issues/301
TypeError: the JSON object must be str, bytes or bytearray, not NoneType · Issue #301 · ssut/py-googletrans
File "/data/leisu/leisu_env/lib/python3.7/site-packages/googletrans/client.py", line 219, in translate parsed = json.loads(data[0][2]) File "/data/local/python3.7/lib/python3.7/json/...
github.com
5000자라는 것은 확인해보니, 5000 단어라는 것이 아니라, `len(text)` 를 했을 때 5000보다 작거나 같아야 한다는 것을 의미하니, 위 오류를 보면 우선 글자수를 확인해보면 좋을 것 같다.
'각종 버그 🐞' 카테고리의 다른 글
[Python] math.log 계산시 ValueError: math domain error (0) | 2023.02.01 |
---|