Escaping confusion with Python 3 + MySQL

Νίκος Βέργος me.on.nzt at gmail.com
Sun Mar 26 10:07:35 EDT 2017


Τη Κυριακή, 26 Μαρτίου 2017 - 5:04:27 μ.μ. UTC+3, ο χρήστης INADA Naoki This error came from MySQL.  If there are no logs in error_log, it's
> your configuration issue.
> 
> See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update
> statement syntax.

cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE "%{}%"'''.format(pID, domain, ref, location, useros, browser, lastvisit, domain) ) 

output of error-log:

[code] 
[Sun Mar 26 16:45:50.940077 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Error in sys.excepthook: 
[Sun Mar 26 16:45:50.940126 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Traceback (most recent call last): 
[Sun Mar 26 16:45:50.940151 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:   File "/usr/local/lib/python3.5/cgitb.py", line 268, in __call__ 
[Sun Mar 26 16:45:50.940166 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:     self.handle((etype, evalue, etb)) 
[Sun Mar 26 16:45:50.940189 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:   File "/usr/local/lib/python3.5/cgitb.py", line 273, in handle 
[Sun Mar 26 16:45:50.940200 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:     self.file.write(reset()) 
[Sun Mar 26 16:45:50.940220 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: ValueError: underlying buffer has been detached 
[Sun Mar 26 16:45:50.940225 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: 
[Sun Mar 26 16:45:50.940235 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Original exception was: 
[Sun Mar 26 16:45:50.940249 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Traceback (most recent call last): 
[Sun Mar 26 16:45:50.940265 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:   File "metrites.py", line 355, in <module> 
[Sun Mar 26 16:45:50.940298 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:     (pID, domain, ref, location, useros, browser, lastvisit, domain) ) 
[Sun Mar 26 16:45:50.940329 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:   File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 144, in execute 
[Sun Mar 26 16:45:50.940343 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:     query = self.mogrify(query, args) 
[Sun Mar 26 16:45:50.940379 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:   File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 135, in mogrify 
[Sun Mar 26 16:45:50.940398 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215:     query = query % self._escape_args(args, conn) 
[Sun Mar 26 16:45:50.940420 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: TypeError: not all arguments converted during string formatting 
[/code]


More information about the Python-list mailing list