MySQL Forums
Forum List  »  Connector/Python

Connector escape strings
Posted by: p4sh eb4sh
Date: September 06, 2018 06:25AM

Good day and have a nice day!
i use mysqlConnector with python 3.6.5

In python i have list:

zipped = [('akamaitechnologies.com', 8221, 0), ('akamaitechnologies.com', 2053, 0), ('googleusercontent.com', 1119, 0), ('1e100.net', 3999, 0), ('1e100.net', 2819, 0)]`

Also i have datasase with simple table:

CREATE TABLE `dns` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`dnsname` text,
`inbytes` int(11) DEFAULT NULL,
`outbytes` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

And my code:

#one function for connect & execute query
def mysql_conn2(fhost, finb, foutb):
cnx = mysql.connector.connect(user=mysql_user, password=mysql_password, database=mysql_database, host=mysql_host)
cursor = cnx.cursor()
cursor.execute("INSERT into dns (`dnsname`,`inbytes`,`outbytes`) VALUES(%s,%s,%s);", (fhost, finb, foutb))
cnx.close()

#my script, that i have ro run
for item in zipped:
host = str(item[0])
inb = str(item[1])
outb = str(item[2])
print(host,inb, outb)
mysql_conn2(host,inb,outb)

But then i check up my table - but there arent any rows! Empty... If i manually add row - that is OK status.
When i debug my script - i see it: IMGUR
I see en error - escaped stings in cursor.statement property, why so?

How can i unescape these rows / may be i do something wrong?
thanks for help!

Options: ReplyQuote


Subject
Written By
Posted
Connector escape strings
September 06, 2018 06:25AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.