소스 검색

fix encoding is none (#394)

tags/0.3.4
Jyong 2 년 전
부모
커밋
b08c19d926
No account linked to committer's email address
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4
    1
      api/controllers/console/datasets/file.py

+ 4
- 1
api/controllers/console/datasets/file.py 파일 보기

with open(filepath, "rb") as fp: with open(filepath, "rb") as fp:
data = fp.read() data = fp.read()
encoding = chardet.detect(data)['encoding'] encoding = chardet.detect(data)['encoding']
text = data.decode(encoding=encoding).strip() if data else ''
if encoding:
text = data.decode(encoding=encoding).strip() if data else ''
else:
text = data.decode(encoding='utf-8').strip() if data else ''


text = text[0:PREVIEW_WORDS_LIMIT] if text else '' text = text[0:PREVIEW_WORDS_LIMIT] if text else ''
return {'content': text} return {'content': text}

Loading…
취소
저장