一、描述
执行python脚本,报如下错误
insert into r_hour_stat_dsp ( day,hour,test,country_code,advertiser_id,order_id,ad_id,mid,publisher_id,app_id,traffic_source,slot_id,bucket_id,up_request_count ) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on duplicate key update up_request_count=Values(up_request_count)
[{'up_request_count': Decimal('61'), 'bucket_id': 'total', 'ad_id': 'a2829410199104', 'hour': 20L, 'order_id': 'o2823322169152', 'traffic_source': 'total', 'mid': 'm2829410199169', 'app_id': 'app263722909504', 'advertiser_id': 'adv2823318381440', 'slot_id': 's1967610014720', 'country_code': 'CH', 'test': 0L, 'publisher_id': 'pub236088034304', 'day': 20200524L}]
Traceback (most recent call last):
File "adx_dsp.py", line 88, in
run(cond_str)
File "adx_dsp.py", line 67, in run
dsp_dim_statistics(official_conn,"r_hour_stat_dsp",cond_str)
File "adx_dsp.py", line 58, in dsp_dim_statistics
conn.execute_many(insert_sql,data[x*BATCH_DELETE_COUNT:(x+1)*BATCH_DELETE_COUNT])
File "/home/sdev/liujichao/py_lib/db.py", line 85, in execute_many
affect_row_num = cursor.executemany(sql, param)
File "/home/sdev/liujichao/MySQLdb/cursors.py", line 253, in executemany
self.errorhandler(self, ProgrammingError, msg.args[0])
File "/home/sdev/liujichao/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: not enough arguments for format string
二、分析
1、如上,为啥报错,%s的个数与参数的个数是一样的
三、解决方法
execute_many(insert_sql,data) data只能是tuple类型(
注意:本文归作者所有,未经作者允许,不得转载