当尝试从anticaptcha函数中访问JSON对象的下标时,该函数中一直出现异常,但所有其他函数似乎都工作正常。
'email':email, 'username': username, 'password': passwd, 'invite': None, 'captcha_key': await anticaptcha.solve(session, 'register')['solution']['gRecaptchaResponse']
TypeError: 'coroutine' object is not subscriptable
async def register(session, username, email, passwd):
"""
sends a request to create an account
"""
async with session.post('http://randomsite.com',
headers={
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0'
},
json={
'email':email, 'username': username, 'password': passwd, 'invite': None, 'captcha_key': await anticaptcha.solve(session, 'register')['solution']['gRecaptchaResponse']
}) as response:
return await response.json()
来自于 anticaptcha 文件的函数
async def task_result(session, task_id):
"""
sends a request to return a specified captcha task result
"""
while True:
async with session.post('https://api.anti-captcha.com/getTaskResult',
json={
"clientKey": ANTICAPTCHA_KEY,
"taskId": task_id
}) as response:
result = await response.json()
if result['errorId'] > 0:
print(colored('Anti-captcha error: ' + result['statusCode']), 'red')
else:
if result['status'] == 'ready':
return await result
async def solve(session, url):
await get_balance(session)
task_id = await create_task(session, url)['taskId']
return await task_result(session, task_id)
(await function())
->dict
。 - D.L