编程语言
首页 > 编程语言> > python3报错:AttributeError: 'builtin_function_or_method' object has no attribute 'randi

python3报错:AttributeError: 'builtin_function_or_method' object has no attribute 'randi

作者:互联网

datas = {"tag": {"name": "长沙" + str(random.randint(10000, 99999))}}

错误提示:AttributeError: 'builtin_function_or_method' object has no attribute 'randint'

使用 random.randint 随机函数时 遇到这个错误

原因:使用引入是 from random import *  或者 from random import random

解决:引入换成 import random

 

    def test_create_flag(self):
        urls = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token="+TestProductApi.access_token
        datas = {"tag": {"name": "长沙" + str(random.randint(10000, 99999))}}
        res = TestProductApi.session.request(method="post",url=urls,json=datas)
        print('==================')
        print(res.json())
        print(json.loads(json.dumps(res.json()).replace(r"\\",'\\')))

  

标签:function,randint,random,json,报错,no,print,import,method
来源: https://www.cnblogs.com/knowledge-poppy/p/16198528.html