Flask Tutorial
の「Step 3: データベースを作成する」で躓いたので忘れないようにやったことをメモ。
init_db()を実行すると、
ValueError: script argument must be unicode.
って怒られる。
db.cursor().executescript(f.read())
→
db.cursor().executescript(f.read().decode('utf-8'))
に書き換えればOK。
must be unicode って言ってるからunicode(utf-8)に変換して上げればOKってことね。
文字コードは難しい…。
参考:https://ikapblg.blog.fc2.com/blog-entry-81.html
2019/05/05 追記
Flaskアプリケーションのテスト でも同様の下記エラーが発生。
assert 'No entries here so far' in rv.data
TypeError: a bytes-like object is required, not 'str'
同じように対応すればエラーが起きなくなりました。
def test_empty_db(self):
rv = self.app.get('/')
assert 'No entries here so far' in rv.data
→
assert 'No entries here so far' in rv.data.decode('utf-8')