python3报错:AttributeError: 'builtin_function_or_method' object has no attribute 'randint'
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"\\",'\\')))