在这个函数中,当我试图将json对象的下标设置为anticaptcha函数的下标时,我总是得到一个异常,但所有其他函数似乎都工作得很好。
'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)
发布于 2018-07-22 04:24:21
await anticaptcha.solve(session, 'register')['solution']['gRecaptchaResponse']
手段
await (anticaptcha.solve(session, 'register')['solution']['gRecaptchaResponse'])
但是你想要
(await anticaptcha.solve(session, 'register'))['solution']['gRecaptchaResponse']
如果另一个类似的东西task_id = await create_task(session, url)['taskId']
正在运行,它可能不会返回未来,您只需设置
task = create_task(session, url)['taskId']
没有await
的话。
https://stackoverflow.com/questions/51459793
复制相似问题