Python 尝试获取url页面时出错

Python 尝试获取url页面时出错,python,django,sqlite,Python,Django,Sqlite,我正在尝试从数据库中获取包含一些数据的url,但我一直遇到以下错误: self = <django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0x7f01c35c2d38> query = ' SELECT cust.id, cust.name, inv.currency_id, SUM(inv.total)\n FROM\n v3_customer as cust\n

我正在尝试从数据库中获取包含一些数据的url,但我一直遇到以下错误:

 self = <django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0x7f01c35c2d38>
query = '        SELECT cust.id, cust.name, inv.currency_id, SUM(inv.total)\n        FROM\n          v3_customer as cust\n    ...        and inv.invoice_date < ?\n        GROUP BY cust.id, inv.currency_id\n        ORDER BY cust.id, inv.currency_id'
params = [(1,), '2016-12-04']

    def execute(self, query, params=None):
        if params is None:
            return Database.Cursor.execute(self, query)
        query = self.convert_query(query)
>       return Database.Cursor.execute(self, query, params)
E       sqlite3.OperationalError: near "?": syntax error

../../../environments/tracerenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py:337: OperationalError
我在这里找到了它失败的地方:

 PRE_INV_Q = """\
    SELECT cust.id, cust.name, inv.currency_id, SUM(inv.total)
    FROM
      v3_customer as cust
      JOIN v3_customerproxy ON cust.id = v3_customerproxy.original_id
      JOIN v3_invoice as inv ON v3_customerproxy.id = inv.customer_id
    WHERE
      cust.id IN %s
      and inv.type = 'i'
      and inv.invoice_date < %s
    GROUP BY cust.id, inv.currency_id
    ORDER BY cust.id, inv.currency_id
PRE_INV_Q=”“”\
选择客户标识、客户名称、存货币种、金额(存货总额)
从…起
v3_客户作为客户
在cust.id=v3\u customerproxy.original\u id上加入v3\u customerproxy
在v3\u customerproxy.id=inv.customer\u id上将v3\u发票作为inv加入
哪里
%s中的客户id
和inv.type='i'
和发票日期<%s
按客户id、库存货币\u id分组
按客户id、库存货币\u id排序的订单

据我所知,convert\u query方法只是替换查询中的参数。请尝试使用
%s
而不是
或者删除
inv.invoice\u data<?\n
处的
?您指的是inv.invoice\u日期吗?请包括完整的回溯和
报告ode>查看.它位于哪里?(很抱歉,我是新手)在您的SQL查询中的部分:
inv.invoice\u date<?\n
。将
替换为
%s
。因此它应该是:
inv.invoice\u date<%s\n
。没有“?“我想你已经编辑了这个问题。否则,它会出现在您发布的问题的第一部分,在
query
中。这个问题还在你身上吗?是的。我只添加了硬编码的sql语句
 PRE_INV_Q = """\
    SELECT cust.id, cust.name, inv.currency_id, SUM(inv.total)
    FROM
      v3_customer as cust
      JOIN v3_customerproxy ON cust.id = v3_customerproxy.original_id
      JOIN v3_invoice as inv ON v3_customerproxy.id = inv.customer_id
    WHERE
      cust.id IN %s
      and inv.type = 'i'
      and inv.invoice_date < %s
    GROUP BY cust.id, inv.currency_id
    ORDER BY cust.id, inv.currency_id