Python TypeError:翻译时需要字符缓冲区对象
我正在从事一个使用sqlite3数据库存储部分数据的项目 我的搜索函数使用SQL语句:Python TypeError:翻译时需要字符缓冲区对象,python,sqlite,python-2.7,dictionary,Python,Sqlite,Python 2.7,Dictionary,我正在从事一个使用sqlite3数据库存储部分数据的项目 我的搜索函数使用SQL语句:''SELECT text FROM snippets which=?'',(whichName,)和我的代码一样,whichName作为字典出现,这导致了以下错误: Traceback (most recent call last): File "snippets.py", line 93, in <module> main() File "snippets.py", line 2
''SELECT text FROM snippets which=?'',(whichName,)
和我的代码一样,whichName
作为字典出现,这导致了以下错误:
Traceback (most recent call last):
File "snippets.py", line 93, in <module>
main()
File "snippets.py", line 24, in main
get_value_from_name(response)
File "snippets.py", line 58, in get_value_from_name
(whichName,))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
当我把字典转换成字符串时。然后,搜索函数返回了None
,因为它通过了[u'TEST']
,而不是像应该通过的那样通过了TEST
。因此,我添加了一些翻译代码:
translation_table = dict.fromkeys(map(ord, '(),'), None)
# Above code creates a table with the mapped characters
name = str(response)
name = name.translate(translation_table)
这就是我目前的问题所在。它返回以下错误:
Traceback (most recent call last):
File "snippets.py", line 93, in <module>
main()
File "snippets.py", line 20, in main
name = name.translate(translation_table)
TypeError: expected a character buffer object
回溯(最近一次呼叫最后一次):
文件“snippets.py”,第93行,在
main()
文件“snippets.py”,第20行,主
name=name.translate(翻译表)
TypeError:应为字符缓冲区对象
我看了这些问题:
- -不适用于我的问题
- -也不适用,因为我的翻译表是从字符串而不是字典创建的
- -也不适用,因为他试图在索引上执行此操作。我试着像它应该做的那样,在整个字符串中查找/替换
谢谢 我解决了这个问题。我在Python3.3.2+中运行了代码,它可以找到(尽管对翻译表进行了一些小的调整)
对不起,我浪费了任何人的时间。我会尽快将此标记为答案。@culix绝对不知道。这个项目是很久以前的事了,所以我对它的记忆不多了。对不起:(
Traceback (most recent call last):
File "snippets.py", line 93, in <module>
main()
File "snippets.py", line 20, in main
name = name.translate(translation_table)
TypeError: expected a character buffer object