【问题标题】:TypeError: not all arguments converted during string formatting - psycopg2TypeError:字符串格式化期间并非所有参数都转换 - psycopg2
【发布时间】:2019-04-23 22:10:22
【问题描述】:

以下查询似乎无法执行并出现错误 - TypeError:并非所有参数都在字符串格式化期间转换。我在哪里错了?

    cursor = connection.cursor()

    cursor.execute("INSERT INTO darkweb (onionurl, sitetext) VALUES(%s, 'test') ON CONFLICT (onionurl) DO NOTHING)", (onion))
    connection.commit() 
    cursor.close()

【问题讨论】:

  • onion的类型和值是什么?
  • onion 也是格式字符串吗?来看看吧
  • 洋葱的类型是

标签: python postgresql psycopg2


【解决方案1】:

您需要在输入元组中添加一个逗号。

cursor = connection.cursor()

cursor.execute("INSERT INTO darkweb (onionurl, sitetext) VALUES(%s, 'test') ON CONFLICT (onionurl) DO NOTHING)", (onion,))
connection.commit() 
cursor.close()

或者你可以这样做:

cursor.execute("INSERT INTO darkweb (onionurl, sitetext) VALUES(%s, 'test') ON CONFLICT (onionurl) DO NOTHING)", [onion])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 2015-10-28
    • 2015-01-21
    • 2013-10-21
    相关资源
    最近更新 更多