AIOXMPP未连接到google hangou

2024-06-25 23:09:21 发布

您现在位置:Python中文网/ 问答频道 /正文

通过google hangout发送消息

这是我的代码,但它在尝试连接时会无休止地等待

你知道怎么“修复”它吗? 短暂性脑缺血发作

import aioxmpp
import asyncio

jid = aioxmpp.JID.fromstr('myuser@gmail.com')
password = 'myPassToGmailAccount'
recipient_jid = aioxmpp.JID.fromstr('recipient_email@gmail.com')

client1 = aioxmpp.PresenceManagedClient(
    jid,aioxmpp.make_security_layer(password))


client1.presence = aioxmpp.PresenceState(available=True, 
 show=aioxmpp.PresenceShow.CHAT)
print (client1.running) # print True

async def send_chat_msg():
    print('hw') # this one is printed and then wait endlessly 
    async with client1.connected() as stream:
        print('hw1') # never print it since hang on the previous command
        msg = aioxmpp.Message(to=recipient_jid,type_=aioxmpp.MessageType.CHAT,)
        msg.body[None] = "Hello World!"
        await client1.send(msg)


if __name__ == '__main__':
    asyncio.run(send_chat_msg())

Tags: importcomsendasynciotruejidmsgpassword