运行init_order_master.py脚本报错
来源:5-8 水平切分演示

codehorsemi
2018-09-27
水平分片搭建完后,运行init_order_master.py脚本报如下错误:
[root@node1 ~]# python init_order_master.py
Traceback (most recent call last):
File “init_order_master.py”, line 34, in
customer_id=int(result[“customer_id”])
TypeError: ‘NoneType’ object has no attribute ‘getitem’
请问这个报错该怎么解决呢?
2回答
-
codehorsemi
提问者
2018-09-27
GetUserID="""
select customer_id,concat(DATE_FORMAT(now(),'%Y%m%d'),left(rand()*1000000,3),right(c
oncat('000',customer_id),3)) as order_sn
from customer_login
order by rand()
limit 1
"""
cursor.execute(GetUserID)
result=cursor.fetchone()
customer_id=int(result["customer_id"])
您好,运行代码至customer_id=int(result["customer_id"])这里就报错了,表示获取不到cutomer_id的值。
customer_id的值是通过customer_login表里面的值获取到的吧,但是库初始化完成后,customer_login表无任何值,所以就会报错吧?
00 -
sqlercn
2018-09-27
先用git库中的bak_imooc.sql脚本初始化一下数据再试一下。这个错误应访介获取不到customer_id值的原因072020-03-15
相似问题