我的代码中有一个令人讨厌的错误,我无法自己弄清楚。这里是我的代码:Python'str'对象不可调用
accounts = open('usernames.txt').read().splitlines()
my_accounts = random.choice(accounts)
for x in my_accounts(starting_account, ending_account, 1):
payload = { 'user_key': get_user_key(),
'terms': 'true',
'action': 'edit',
'page': 'simple',
'flow': 'TestA',
'dob': '1987-22-01',
'gender': 'f',
'name': str(x),
'password': create_password()}
r = requests.post(CONST_URL + end_point, headers=headers, cookies=cookies, data=payload, allow_redirects=False, verify=False)
if r.status_code == 302:
accounts_output = 'accounts.txt'
f = open(accounts_output, 'w')
user_output = (str(r.status_code) + ' Account created succesfully: ' + str(x) + ' ' + create_password())
f.write(user_output)
f.close()
else:
print(str(r.status_code) + ' Unable to connect to the server :/')
print(r.content)
当我尝试运行此我得到以下错误:
Traceback (most recent call last):
File "C:/Users/Google Drive/testing/moreTesting.py", line 66, in <module>
ms = accountCreator().account_creator(0, 5)
File "C:/Users/Pieperloy/Google Drive/testing/moreTesting.py", line 43, in account_creator
for x in my_accounts(starting_account, ending_account, 1):
TypeError: 'str' object is not callable
而且,是的,我曾尝试查找问题,但没有发现任何东西,可以帮助我与我的具体情况。在此先感谢,祝你有个美好的一天
嗯......你确定'str'没有被定义为某个变量吗?否则,您的代码应该工作 – Zizouz212
您的错误消息和这里发布的代码都参考不同的代码!你的错误信息包含'str(ending_account)'和'str(starting_account)',你在这里写的代码不会。请发布正确的代码片段。 –
@soon:my_accounts呢? –