私のDjangoアプリケーションでは、テキストファイルを読み込んでいて、 mysqlデータベース。私のデータベースはUTF-8エンコーディングをサポートしていますが、私は次のエラーを取得する:不正な文字列値: ' xE0 xB9 x82 xE0 xB8 xA3 ...'行1の 'text'列
Exception Type: Warning at /upload Exception Value: Incorrect string value: '\xE0\xB9\x82\xE0\xB8\xA3...' for column 'text' at row 1
Pythonでユニコードに変換コードはここにある:
fileobj = self.request.FILES.get('filepath', None)
filetext = unicode(fileobj.read(), 'utf-8')
uploadedText = models.UploadedText()
uploadedText.text = filetext uploadedText.save()