sqlalchemy.exc.InterfaceError绑定参数1错误

时间:2016-02-20 12:30:56

标签: python sqlalchemy

我尝试执行以下操作:

def EMA(file):

current_time = datetime.datetime.utcnow()
five_minutes_ago = current_time - datetime.timedelta(minutes=5)
sub_within_las_five_min = db.session.query(visits).filter((visits.date > five_minutes_ago),(visits.name == file)).all()
a = len(sub_within_las_five_min)
return a

我收到以下错误:

InterfaceError:(sqlite3.InterfaceError)错误绑定参数1 - 可能不支持的类型。 [SQL:u'SELECT visits.id AS visits_id,visits.name AS visits_name,visits.date AS visits_date \ nFROM visits \ nWHERHER visits.date> ? AND visits.name =?'] [参数:('2016-02-20 12:06:43.974000',(u'vagrant.txt',))]

我知道这个问题是由(u'vagrant.txt')引起的,因为我试图把'vagrant.txt'代替文件而且它有效。从该视图生成文件名:

  @app.route('/api/test/', methods=['GET'])
  def catalogue1():
  catalogue = db.session.query(Content.name).all()
  for i in range(len(catalogue)):
    j= catalogue[i]
    s = EMA(j)
    return str(s) 

我的模特是:

   class visits(db.Model):

   __tablename__ = 'visits'

   id = db.Column(db.Integer, primary_key=True)
   name = db.Column(db.String(20))
   date = db.Column(db.DateTime, default=datetime.datetime.utcnow)


   class Content(db.Model):

    __tablename__ = 'Content'
    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.String(20))
    name = db.Column(db.String(20))
    type = db.Column(db.String(20))
    Hits = db.Column(db.Integer)
    Server_id = db.Column(db.Integer, db.ForeignKey('Server.id'))
    harddrive_id = db.Column(db.Integer, db.ForeignKey('harddrive.id'))

有人可以帮忙!

0 个答案:

没有答案