Есть такой скрипт:
import pymysql, json
#Подключаемся к MYSQL
conn = pymysql.connect(host='localhost', port=3306,
user='root', passwd='nemate666', db='data_map')
cursor = conn.cursor(pymysql.cursors.DictCursor)
#Создаём таблицу
cursor.execute("CREATE TABLE IF NOT EXISTS data_load (project_name TEXT, countryname TEXT, lendprojectcost TEXT)")
#Декодируем json
with open('world_bank.json', 'r') as json_line:
datastore = json.load(json_line)
#Вставляем данные в MYSQL
for line in datastore:
cursor.execute("INSERT INTO data_load (project_name, countryname, lendprojectcost) VALUES (%s %s %s)", (line["project_name"], line["countryname"], str(line["lendprojectcost"])))
cursor.close()
#Закрываем соединение
conn.close()
Трейсбэк:
Traceback (most recent call last):
File "data_load.py", line 21, in <module>
cursor.execute("INSERT INTO data_load (project_name, countryname, lendprojectcost) VALUES (%s %s %s)", (line["project_name"], line["countryname"], str(line["lendprojectcost"])))
File "/home/sergey/virtenvs/visual_env/lib/python3.5/site-packages/pymysql/cursors.py", line 165, in execute
result = self._query(query)
File "/home/sergey/virtenvs/visual_env/lib/python3.5/site-packages/pymysql/cursors.py", line 321, in _query
conn.query(q)
File "/home/sergey/virtenvs/visual_env/lib/python3.5/site-packages/pymysql/connections.py", line 860, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/sergey/virtenvs/visual_env/lib/python3.5/site-packages/pymysql/connections.py", line 1061, in _read_query_result
result.read()
File "/home/sergey/virtenvs/visual_env/lib/python3.5/site-packages/pymysql/connections.py", line 1349, in read
first_packet = self.connection._read_packet()
File "/home/sergey/virtenvs/visual_env/lib/python3.5/site-packages/pymysql/connections.py", line 1018, in _read_packet
packet.check_error()
File "/home/sergey/virtenvs/visual_env/lib/python3.5/site-packages/pymysql/connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "/home/sergey/virtenvs/visual_env/lib/python3.5/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.InternalError: (1136, "Column count doesn't match value count at row 1")
Как это можно решить? Где ошибаюсь?