TypeError: can't concat bytes to tuple

976 views
Skip to first unread message

Adarsh Sharma

unread,
Oct 27, 2014, 7:29:30 PM10/27/14
to django...@googlegroups.com
Hi all,

I am running below program : http://palewi.re/posts/2008/04/26/python-recipe-connect-to-mysql-database-execute-a-query-print-the-results/

on Centos 6.4 , Python 3.4 but not sure why it is failing with below exception :

root@db2 bin]# python printfields_new.py datbase1 tb_sime_darby
Wikified HTML for adunit.tb_sime_darby
========================
Traceback (most recent call last):
  File "printfields_new.py", line 33, in <module>
    PrintFields(users_database, users_table)
  File "printfields_new.py", line 12, in PrintFields
    mysql.execute(sql)
  File "/usr/local/lib/python3.4/site-packages/pymysql/cursors.py", line 132, in execute
    result = self._query(query)
  File "/usr/local/lib/python3.4/site-packages/pymysql/cursors.py", line 271, in _query
    conn.query(q)
  File "/usr/local/lib/python3.4/site-packages/pymysql/connections.py", line 725, in query
    self._execute_command(COM_QUERY, sql)
  File "/usr/local/lib/python3.4/site-packages/pymysql/connections.py", line 888, in _execute_command
    self._write_bytes(prelude + sql[:chunk_size-1])
TypeError: can't concat bytes to tuple

Anyone has any idea about this ? Also , how can we make sure to prevent from Identation erros in python ?

Thanks

Vijay Khemlani

unread,
Oct 27, 2014, 9:13:56 PM10/27/14
to django...@googlegroups.com
Well, this is not a Django-related question, but still.

The tutorial you are following uses Python 2.5.1, which differs a lot from the Python 3.4 that you are using. If you want to still follow that tutorial you'd better install Python 2.7, which is more compatible with 2.5

Also, try printing the query (the sql variable in your case) before executing it in mysql and check if it is right (in particular that it is actually a string and not a list, tuple, or something else)

Regards!



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54bfc5a3-1336-4c26-ad49-8af2a2da4ab8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages