I have been developing a program for a bit now and so far it was working for me, until now. For some weird reason when I run it this error pops up out of nowhere. I really tried everything by now and don't know whats the issue. Somebody please help.
The code is quite long so I will post the part where the problem most likely exists, but I can post the rest if its needed.
if p["op"] == "hello":
await self.send({"op": "init", "encoded_public_key": self.publicKeyString}, ws)
self._heartbeatTask = asyncio.get_event_loop().create_task(self.sendHeartbeat(p["heartbeat_interval"], ws))
elif p["op"] == "nonce_proof":
nonceHash = hashlib.sha256()
nonceHash.update(self.privateKey.decrypt(base64.b64decode(bytes(p["encrypted_nonce"], "utf8")), padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None)))
nonceHash = base64.urlsafe_b64encode(nonceHash.digest()).decode("utf8")
nonceHash = nonceHash.replace("/", "").replace("+", "").replace("=", "")
await self.send({"op": "nonce_proof", "proof": nonceHash}, ws)
elif p["op"] == "pending_remote_init":
await self.on_fingerprint(data=f"https://discordapp.com/ra/{p['fingerprint']}")
elif p["op"] == "pending_finish":
decryptedUser = self.privateKey.decrypt(base64.b64decode(bytes(p["encrypted_user_payload"], "utf8")), padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None)).decode("utf8")
decryptedUser = decryptedUser.split(":")
await self.on_userdata(user=User(decryptedUser[0], decryptedUser[3], decryptedUser[1], decryptedUser[2]))
elif p["op"] == "finish":
await self.on_token(token=self.privateKey.decrypt(base64.b64decode(bytes(p["encrypted_token"], "utf8")), padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None)).decode("utf8"))
break
elif p["op"] == "cancel":
await self.on_cancel()
break
214. self._heartbeatTask.cancel() // This the line with error.
if error:
print(f"{y}[{Fore.LIGHTRED_EX}!{y}]{w} RemoteAuthClient disconnected with error. Reconnecting...")
self.initCrypto()
await self.run()
async def sendHeartbeat(self, interval, _ws):
while True:
await asyncio.sleep(interval/1000)
await self.send({"op": "heartbeat"}, _ws)
async def send(self, jsonr, _ws):
await _ws.send(json.dumps(jsonr))
c = RemoteAuthClient()
The error happens to be in the line 214:
//ERROR MESSAGE
File "...", line 214, in run
self._heartbeatTask.cancel()
AttributeError: 'NoneType' object has no attribute 'cancel'
On God, any help is appriciated!!