Python 使用sleekxmpp发送消息挂起在进程()中

Python 使用sleekxmpp发送消息挂起在进程()中,python,sleekxmpp,Python,Sleekxmpp,所以我有一个小Python脚本,它从PostgreSQL表的插入中触发,并传递XMPP消息。工作得很有魅力。现在升级到Python 3.8(从3.5版)和sleekxmpp 1.3.3版。(之前的1.3.1)我有一个问题:它挂在process()中 这是我的剧本: #!/usr/bin/env python # -*- coding: utf-8 -*- import psycopg2.extensions import select import sys import logging imp

所以我有一个小Python脚本,它从PostgreSQL表的插入中触发,并传递XMPP消息。工作得很有魅力。现在升级到Python 3.8(从3.5版)和sleekxmpp 1.3.3版。(之前的1.3.1)我有一个问题:它挂在
process()

这是我的剧本:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import psycopg2.extensions
import select
import sys
import logging
import getpass
from optparse import OptionParser

import sleekxmpp

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

import django
django.setup()

from unplug.models import Xmpp
from django.db import connection

cursor=connection.cursor()
pg_con=connection.connection

logging.basicConfig(filename='sendXMPPpy.log', level=logging.DEBUG)

if sys.version_info < (3, 0):
    reload(sys)
    sys.setdefaultencoding('utf8')
else:
    raw_input = input


class SendMsgBot(sleekxmpp.ClientXMPP):
    def __init__(self, jid, password, recipient, message):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)
        self.recipient = recipient
        self.msg = message
        self.add_event_handler("session_start", self.start)

    def start(self, event):
        self.send_presence()
        self.get_roster()
        if self.msg =="":
            # bei leerer Message wird er Empfaenger gebucht ...
            self.update_roster(recipient,block=False,subscription="to")
        else:
            self.send_message(mto=self.recipient,
                                    mbody=self.msg,
                                    mtype='chat')
        self.disconnect(wait=True)


def send_XMPP(target,message):
    print("send_XMPP()")
    xmpp = SendMsgBot("YYY@jabber.de", "XXX", target,message)
    xmpp.register_plugin('xep_0030') # Service Discovery
    xmpp.register_plugin('xep_0199') # XMPP Ping
    if xmpp.connect():
        xmpp.process(block=True)  # here it hangs!
        print("Done")
    else:
        print("Unable to connect.")

if __name__ == '__main__':

cursor.execute('LISTEN xmpp')

while 1:
    if select.select([pg_con],[],[],5) == ([],[],[]):
        pass
    else:
        pg_con.poll()
        while pg_con.notifies:
        notify = pg_con.notifies.pop(0)

        for sx in Xmpp.objects.all():
            send_XMPP(sx.target,' ' if sx.mBody == '' else sx.mBody)
            sx.delete()

所以我推测“无效证书信任链”是罪魁祸首。但是如何避免这种情况呢?

好的,看来我已经解决了这个问题——不知道失败的具体原因:

我刚刚从sleekxmpp版本1.3.3退到版本1.3.1。现在它和以前一样工作

。。。为了记录在案-刚刚发现sleekXMPP已被弃用-请参见此处:

DEBUG:sleekxmpp.xmlstream.xmlstream:Event triggered: session_end
DEBUG:sleekxmpp.xmlstream.xmlstream:Event triggered: disconnected
DEBUG:sleekxmpp.thirdparty.statemachine: ==== TRANSITION connected -> disconnected
ERROR:sleekxmpp.xmlstream.xmlstream:Can not read from closed socket.
DEBUG:sleekxmpp.xmlstream.xmlstream:reconnecting...
DEBUG:sleekxmpp.xmlstream.xmlstream:connecting...
DEBUG:sleekxmpp.xmlstream.xmlstream:Waiting 2.1448919023898796 seconds before connecting.
DEBUG:sleekxmpp.xmlstream.xmlstream:No remaining DNS records to try.
DEBUG:sleekxmpp.xmlstream.xmlstream:Waiting 3.819744501097285 seconds before connecting.
WARNING:sleekxmpp.xmlstream.resolver:DNS: dnspython not found. Can not use SRV lookup.
DEBUG:sleekxmpp.xmlstream.resolver:DNS: Querying jabber.de for AAAA records.
DEBUG:sleekxmpp.xmlstream.resolver:DNS: Querying jabber.de for A records.
DEBUG:sleekxmpp.xmlstream.xmlstream:Connecting to [2a01:238:42b4:2600:a44f:27fe:6a8a:cd3c]:5222
DEBUG:sleekxmpp.xmlstream.xmlstream:Event triggered: connected
DEBUG:sleekxmpp.thirdparty.statemachine: ==== TRANSITION disconnected -> connected
DEBUG:sleekxmpp.xmlstream.xmlstream:SEND (IMMED): <stream:stream to='jabber.de' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>
DEBUG:sleekxmpp.xmlstream.xmlstream:RECV: <stream:stream from="jabber.de" version="1.0" id="dcdb99e5-ef47-4a89-8925-522617c39432" xml:lang="en">
DEBUG:sleekxmpp.xmlstream.xmlstream:RECV: <stream:features xmlns="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required /></starttls></stream:features>
DEBUG:sleekxmpp.xmlstream.xmlstream:SEND (IMMED): <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required /></starttls>
DEBUG:sleekxmpp.xmlstream.xmlstream:RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
DEBUG:sleekxmpp.features.feature_starttls.starttls:Starting TLS
INFO:sleekxmpp.xmlstream.xmlstream:Negotiating TLS
INFO:sleekxmpp.xmlstream.xmlstream:Using SSL version: TLSv1
ERROR:sleekxmpp.xmlstream.xmlstream:CERT: Invalid certificate trust chain.
DEBUG:sleekxmpp.xmlstream.xmlstream:Event triggered: session_end
DEBUG:sleekxmpp.xmlstream.xmlstream:Event triggered: disconnected
DEBUG:sleekxmpp.thirdparty.statemachine: ==== TRANSITION connected -> disconnected
ERROR:sleekxmpp.xmlstream.xmlstream:Can not read from closed socket.
DEBUG:sleekxmpp.xmlstream.xmlstream:reconnecting...
DEBUG:sleekxmpp.xmlstream.xmlstream:connecting...
DEBUG:sleekxmpp.xmlstream.xmlstream:Waiting 2.2652390846224826 seconds before connecting.
DEBUG:sleekxmpp.xmlstream.xmlstream:Stopped event runner thread. 2 threads remain.
DEBUG:sleekxmpp.xmlstream.xmlstream:Stopped send thread. 1 threads remain.
DEBUG:sleekxmpp.xmlstream.scheduler:Quitting Scheduler thread
DEBUG:sleekxmpp.xmlstream.xmlstream:Stopped scheduler thread. 0 threads remain.