所以我正在尝试制作一个以我的世界为名的狙击手,但它向我抛出了这个错误:
RuntimeError: Event loop stopped before Future completed.
我的代码:
import asyncio
import aiohttp
tokenlist = ['token1','token2','token3','token4','token5']
name = 'bruh'
async def send_requests():
coros = [
snipe_req(token) for token in tokenlist for x in range(3)
]
await asyncio.wait(coros)
async def snipe_req(token):
await asyncio.sleep(0)
async with aiohttp.ClientSession().put(f"https://api.minecraftservices.com/minecraft/profile/name/{name}",headers={"Authorization": "Bearer " + token,"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0","Content-Type": "application/json"}) as response:
await response.read()
print(response)
asyncio.get_event_loop().stop()
def run():
loop = asyncio.get_event_loop()
loop.run_until_complete(send_requests())
run()
有人知道这里的问题在哪里吗?
答案 0 :(得分:0)
你必须先打开 session,然后使用 put 方法。
import asyncio
import aiohttp
tokenlist = ['token1','token2','token3','token4','token5']
name = 'bruh'
async def send_requests():
coros = [
snipe_req(token) for token in tokenlist for x in range(3)
]
await asyncio.wait(coros)
async def snipe_req(token):
async with aiohttp.ClientSession() as client:
session = await client.put(
f"https://api.minecraftservices.com/minecraft/profile/name/{name}",
headers={
"Authorization": "Bearer " + token,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0",
"Content-Type": "application/json"
})
await session.read()
print(session)
def run():
loop = asyncio.get_event_loop()
loop.run_until_complete(send_requests())
run()