我已经使用 Django 构建了一个站点,当我尝试执行查询时收到了这个烦人的错误。

如果我重新启动 Apache 服务器,错误将消失一小段时间。

Traceback:
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/home/fran/cron/views/set_caches.py" in set_caches
24.         cursor.execute(query, [category['id']])
File "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
15.             return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py" in execute
86.             return self.cursor.execute(query, args)
File "build/bdist.linux-i686/egg/MySQLdb/cursors.py" in execute
155.         charset = db.character_set_name()

Exception Type: InterfaceError at /blablabla/
Exception Value: (0, '')

最佳答案

这是由全局游标引起的。尝试在需要原始查询的每个方法中创建和关闭游标。

cursor = connection.cursor()
cursor.execute(query)
cursor.close()

关于python - 接口(interface)错误 (0, ''),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6650940/

10-15 11:51