擅长:python、mysql、java
<p>虽然最初的作者很可能已经离开了,但我想我会在这里留下一个答案给未来的谷歌用户(比如我)。</p>
<p>我想这里发生的是下面的错误。。。</p>
<p><code>ValueError: parameters are of unsupported type</code></p>
<p>。。。实际上是来自下面的一行(与作者所说的相反)。</p>
<pre><code>s = c.execute("select score from score where id=?", id)
</code></pre>
<p>这里的问题是<code>Cursor.execute</code>接受查询字符串作为第一个参数(他有权这样做),<strong>但是<code>list</code>,<code>tuple</code>,或者<code>dict</code>作为第二个参数。在这种情况下,他需要将这个<code>id</code>包装成元组或列表,如下所示:</p>
<pre><code>s = c.execute("select score from score where id=?", (id,))
</code></pre>
<p>列表或元组可以与位置参数一起使用(当您使用问号<code>?</code>作为占位符时)。还可以对命名参数使用<code>dict</code>和<code>:key</code>,如下所示:</p>
<pre><code>s = c.execute("select score from score where id=:id", {"id": id})
</code></pre>