格式字符串的参数不足

时间:2016-01-14 15:57:44

标签: python python-2.7 sqlalchemy

我正在尝试使用SQLAlchemy

执行查询
dev_engine = create_engine('mysql://...')

dev_connect = dev_engine.connect()
prod_connect = prod_engine.connect()


get_dev_instrument = "select * from market_instrument inner join cme_instrument on market_instrument.id = cme_instrument.instrument_id \
inner join tick_size on market_instrument.id = tick_size.instrument_id \
left join futures on market_instrument.id = futures.instrument_id \
left join `options`on market_instrument.id = `options`.instrument_id \
left join spreads on market_instrument.id = spreads.instrument_id \
inner join (select distinct(substring(m.symbol, 1, 2)) as product from market_instrument as m inner join fills as f on m.id=f.instrument_id \
inner join cme_instrument where symbol<>\"\" and fill_timestamp between CURDATE() - INTERVAL 60 DAY AND NOW()) r \
on market_instrument.symbol like concat(r.product, \'%\') \
where symbol not like \'%_old%\' and symbol not like \'%:%\';"

instruments = dev_engine.execute(get_dev_instrument)

我不断获得TypeError: not enough arguments for format string

Traceback (most recent call last):
  File "check_instrument_transactions-cme.py", line 122, in <module>
    main()
  File "check_instrument_transactions-cme.py", line 120, in main
    transactions(exchange, last_days, filepath)
  File "check_instrument_transactions-cme.py", line 28, in transactions
    instruments = dev_engine.execute(get_dev_instrument)
  File "/home/local/filepath/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1991, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/home/local/filepath/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 906, in execute
    return self._execute_text(object, multiparams, params)
  File "/home/local/filepath/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
    statement, parameters
  File "/home/local/filepath/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/home/local/filepath/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1344, in _handle_dbapi_exception
    util.reraise(*exc_info)
  File "/home/local/filepath/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/home/local/filepath/anaconda2/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
  File "/home/local/filepath/anaconda2/lib/python2.7/site-packages/MySQLdb/cursors.py", line 187, in execute
    query = query % tuple([db.literal(item) for item in args])
TypeError: not enough arguments for format string

我看了这个错误,但它说要传递你想格式化为元组的字符串,这个错误似乎是底层API的一部分,而不是我的代码。有什么问题?我在使用相同的确切代码之前运行了类似的长度查询,并且我没有这样做。

0 个答案:

没有答案