From ec2d3014404db5c130a8c73ade5a114f4150c9a2 Mon Sep 17 00:00:00 2001 From: Will James Date: Sat, 28 Feb 2015 16:41:15 +1100 Subject: [PATCH] Need to use surrogate escape here too I think If bytes get passed in they are escaped using escape_bytes with a `surrogateescape` but then are not encoded properly here without this change. This seems to fix the issue for me. --- pymysql/connections.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index 8f5756b..d9eb4a1 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -760,7 +760,10 @@ class Connection(object): #if DEBUG: # print("DEBUG: sending query:", sql) if isinstance(sql, text_type) and not (JYTHON or IRONPYTHON): - sql = sql.encode(self.encoding) + if PY2: + sql = sql.encode(self.encoding) + else: + sql = sql.encode(self.encoding, 'surrogateescape') self._execute_command(COMMAND.COM_QUERY, sql) self._affected_rows = self._read_query_result(unbuffered=unbuffered) return self._affected_rows