向数据库添加记录时字符串值不正确

e4eetjau  于 2021-06-19  发布在  Mysql
关注(0)|答案(0)|浏览(239)

我正在尝试将以下词典正确地添加到数据库中:

{'genres': 'Horror', 'description': u'Vampire Count Orlok is interested in a new residence and in his real estate agent\u2019s young wife. F.\u202fW. Murnau\u2019s unauthorized adaptation of Bram Stoker\u2019s \u201cDracula.\u201d', 'year': u'1922-03-15', 'id': 653, 'title': 'Nosferatu (Nosferatu, eine Symphonie des Grauens) (1922)'}

但我得到以下错误:

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, u"Incorrect string value: '\\xE2\\x80\\xAFW. ...' for column 'description' at row 1") [SQL: u'INSERT INTO movies (id, title, description, year) VALUES (%(id)s, %(title)s, %(description)s, %(year)s)'] [parameters: {'id': 653, 'title': 'Nosferatu (Nosferatu, eine Symphonie des Grauens) (1922)', 'description': u'Vampire Count Orlok is interested in a new residence and in his real estate agent\u2019s young wife. F.\u202fW. Murnau\u2019s unauthorized adaptation of Bram Stoker\u2019s \u201cDracula.\u201d', 'year': u'1922-03-15'}] (Background on this error at: http://sqlalche.me/e/2j85)

引擎连接参数包括:

engine = create_engine(url, connect_args={'charset':'utf8mb4'})

但还是什么都没有。如何绕过它?
代码是纯请求用法:

//movie is a dictionary containing the id of the movie and the title.
//TMDB is used to download additional info like the overview and release_year, and I update the initial dictionary. Some movie ids were able to store in db.

url = 'https://api.themoviedb.org/3/movie/{}?api_key={}'.format(
       movie['id'], api_key)

req = requests.get(url, data={})
resp = req.json()
movie['description'] = resp.get('overview')

movie['year'] = resp.get('release_date')

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题