Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
处理pyformat参数失败';MySQLConverter';对象没有属性'_列表到mysql';_Mysql_Python 2.7 - Fatal编程技术网

处理pyformat参数失败';MySQLConverter';对象没有属性'_列表到mysql';

处理pyformat参数失败';MySQLConverter';对象没有属性'_列表到mysql';,mysql,python-2.7,Mysql,Python 2.7,我有一个python脚本,每次进行wait_for_页面调用时,它都会将等待页面的时间写入数据库。查询如下: conn = mysql.connector.connect(**config) connect = conn.cursor() params = {'build': self.tc.tag, 'page': unicode(self), 'object_id': self.object_id, 'page_header': self.

我有一个python脚本,每次进行wait_for_页面调用时,它都会将等待页面的时间写入数据库。查询如下:

    conn = mysql.connector.connect(**config)
    connect = conn.cursor()
    params = {'build': self.tc.tag, 'page': unicode(self), 'object_id': self.object_id, 'page_header':
              self.page_header, 'interval': t.interval, 'timestamp': timestamp}
    query = u'INSERT INTO page_load_times (build, page, object_id, page_header, elapsed_time, date_run) ' \
            'VALUES (%(build)s, %(page)s, %(object_id)s, %(page_header)s, %(interval)s, %(timestamp)s)'
    connect.execute(query, params)
    conn.commit()
    conn.close()
有时,当运行此命令时,我会收到一个错误,该错误表示:

 "Failed processing pyformat-parameters; %s" % err)
 ProgrammingError: Failed processing pyformat-parameters; 'MySQLConverter' 
 object has no attribute '_list_to_mysql'
我知道这是什么原因,只是不确定如何着手解决它。
“page”:unicode(self)
参数偶尔会得到一个列表

为了解决这个问题,我调整了上面的脚本,将列表提取为字符串,如下所示:

    page_list = u'{}'.format(self)
    page_results = "('%s')" % "','".join(page_list)
    params = {'build': self.tc.tag, 'page': page_results, 'object_id': self.object_id, 'page_header':
              self.page_header, 'interval': t.interval, 'timestamp': timestamp}
当我运行这个时,我现在得到的错误是数据对于字段来说太长。我调试它,发现我的页面结果中每个字符都被单独解析出来,如下所示:

u'(\\'A\\',\\'p\\',\\'p\\',\\'M\\',\\'a\\',\\'i\\',\\'n\\',\\'M\\',\\'e\\',\\'n\\',\\'u\\',\\':\\',\\' \\',\\'N\\',\\'o\\',\\'n\\',\\'e\\')'

因此,解决方案是执行以下操作,即获取页面_标题,如果它位于列表实例中,则将该列表设置为字符串:

    conn = mysql.connector.connect(**config)
    connect = conn.cursor()
    page_list = u'{}'.format(self)
    page_header_list = u'{}'.format(self.page_header)

    if isinstance(page_header_list, list):
        page_header_list = ', '.join(page_header_list)[0:100]

    params = {'build': self.tc.tag, 'page': page_list, 'object_id': self.object_id,
              'page_header': page_header_list, 'interval': t.interval, 'timestamp': timestamp}
    query = u'INSERT INTO page_load_times (build, page, object_id, page_header, elapsed_time, date_run) ' \
            'VALUES (%(build)s, %(page)s, %(object_id)s, %(page_header)s, %(interval)s, %(timestamp)s)'
    connect.execute(query, params)
    conn.commit()
    conn.close()

谢谢你@DarthOpto,你给了我很多光明。我通过在变量周围放置
srt
解决了这个问题:

params = {'build': self.tc.tag, 'page': srt(page_list),'object_id': self.object_id,
          'page_header': srt(page_header_list),'interval': t.interval,'timestamp': timestamp}