LoginSignup
8
2

More than 3 years have passed since last update.

Flaskチュートリアル「Step 3: データベースを作成する」で躓いたことのメモ

Last updated at Posted at 2019-05-02

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')
8
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2