Python - pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1)

Autor Kujón
Publikováno 05.08.2020
Kategorie programovani
Stav Vyřešeno
Dobrý den,

učím se s Pythonem pracovat s MySQL datábází přes doplněk PyMySQL. Když použiji kód níže, tak dostanu chybu:

pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1).

Poradíte prosím někdo co s tím? Děkuji

Python část kódu



now = datetime.today()
log([0, 'xyz_ht', 'run', 'xyz_ht', 'ht.py', 'root', now])


Funkce



# logovani
def log(log):
con = mysql.connect(**config)
with con:
cur = con.cursor()
sql = str("INSERT INTO logs (`log_bond`, `log_table`, `log_operation`, `log_data`, `log_subdata`, `log_user`, `log_date`) \
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')" \
.format(log[0], log[1], log[2], log[3], log[4], log[5]))

cur.execute(sql)
con.commit()


Chyba:



Traceback (most recent call last):
File "/var/xyz/ht.py", line 198, in
log([1, 'xyz_ht', 'run', 'xyz_ht', 'ht.py', now])
File "/var/xyz/ht.py", line 70, in log
cur.execute(sql)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/cursors.py", line 166, in execute
result = self._query(query)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 856, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1057, in _read_query_result
result.read()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1340, in read
first_packet = self.connection._read_packet()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1014, in _read_packet
packet.check_error()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/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")


Odpovědi na dotaz 1

The English language is translated by machine - the translator can modify eg cited codes = it is better to use codes from the Czech original.

Python - pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1)

Hi,

I'm learning to work with Python with MySQL databases via the PyMySQL add-on. If I use the code below, I get an error:

pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1) .

Can someone please advise what to do with it? Thank you

Python piece of code



now = datetime.today()
log([0, 'xyz_ht', 'run', 'xyz_ht', 'ht.py', 'root', now])


Method



# logovani
def log(log):
con = mysql.connect(**config)
with con:
cur = con.cursor()
sql = str("INSERT INTO logs (`log_bond`, `log_table`, `log_operation`, `log_data`, `log_subdata`, `log_user`, `log_date`) \
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')" \
.format(log[0], log[1], log[2], log[3], log[4], log[5]))

cur.execute(sql)
con.commit()


Error



Traceback (most recent call last):
File "/var/xyz/ht.py", line 198, in
log([1, 'xyz_ht', 'run', 'xyz_ht', 'ht.py', now])
File "/var/xyz/ht.py", line 70, in log
cur.execute(sql)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/cursors.py", line 166, in execute
result = self._query(query)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 856, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1057, in _read_query_result
result.read()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1340, in read
first_packet = self.connection._read_packet()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1014, in _read_packet
packet.check_error()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/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")

RE: Python - pymysql.err.InternalError: (1136, Column…

Autor OL3G
Publikováno 18.08.2020
Kategorie programovani
Stav Zkontrolováno
Dobrý den,

chyba Column count doesn't match value count at row v tomto případě znamená, že nesouhlasí index pole = chybí tam log[6] .

Takže správně takto:

# logovani
def log(log):
con = mysql.connect(**config)
with con:
cur = con.cursor()
sql = str("INSERT INTO logs (`log_bond`, `log_table`, `log_operation`, `log_data`, `log_subdata`, `log_user`, `log_date`) \
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')" \
.format(log[0], log[1], log[2], log[3], log[4], log[5], log[6]))

cur.execute(sql)
con.commit()


1

The English language is translated by machine - the translator can modify eg cited codes = it is better to use codes from the Czech original.

Python - pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1)

Hi,

the error Column count doesn't match value value at row in this case means that the field index does not match = log[6] is missing here.

So right like this:

# logovani
def log(log):
con = mysql.connect(**config)
with con:
cur = con.cursor()
sql = str("INSERT INTO logs (`log_bond`, `log_table`, `log_operation`, `log_data`, `log_subdata`, `log_user`, `log_date`) \
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')" \
.format(log[0], log[1], log[2], log[3], log[4], log[5], log[6]))

cur.execute(sql)
con.commit()
Tento web používá k poskytování služeb, personalizaci reklam a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tím souhlasíte. Další informace