我正在尝试将以下字典移至数据库:
{'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_connection参数为:
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')