我已经在stackoverflow中阅读了几个文档和帖子,我找不到使用sleekxmpp
发送文件或图片的任何示例。我已阅读file_transfer.py
中提供的sleekxmpp
中的代码包,但我无法使用该代码。如果有人或通过sleekxmpp发送文件的例子,请告诉我。谢谢提前!
这是我尝试使用sleekxmpp发送文件的代码
import logging
from sleekxmpp import Iq, Message
from sleekxmpp.plugins import BasePlugin
from sleekxmpp.xmlstream.handler import Callback
from sleekxmpp.xmlstream.matcher import StanzaPath
from sleekxmpp.xmlstream import register_stanza_plugin, JID
from sleekxmpp.plugins.xep_0096 import stanza, File
log = logging.getLogger(__name__)
class XEP_0096(BasePlugin):
name = 'xep_0096'
description = 'XEP-0096: SI File Transfer'
dependencies = set(['xep_0095'])
stanza = stanza
def plugin_init(self):
register_stanza_plugin(self.xmpp['xep_0095'].stanza.SI, File)
self.xmpp['xep_0095'].register_profile(File.namespace, self)
def session_bind(self, jid):
self.xmpp['xep_0030'].add_feature(File.namespace)
def plugin_end(self):
self.xmpp['xep_0030'].del_feature(feature=File.namespace)
self.xmpp['xep_0095'].unregister_profile(File.namespace, self)
def request_file_transfer(self, jid, sid=None, name=None, size=None,
desc=None, hash=None, date=None,
allow_ranged=False, mime_type=None,
**iqargs):
data = File()
data['name'] = name
data['size'] = size
data['date'] = date
data['desc'] = desc
if allow_ranged:
data.enable('range')
return self.xmpp['xep_0095'].offer(jid,
sid=sid,
mime_type=mime_type,
profile=File.namespace,
payload=data,
**iqargs)
当我执行上面的例子时,我得到了以下错误
ERROR Error processing event handler: >
Traceback (most recent call last):
File "d:\Python27\lib\site-packages\sleekxmpp\xmlstream\xmlstream.py", line 1699, in _event_runner
func(*args)
File "send_file.py", line 69, in start
stream = self['xep_0047'].open_stream(self.receiver)
File "d:\Python27\lib\site-packages\sleekxmpp\plugins\xep_0047\ibb.py", line 143, in open_stream
resp = iq.send(timeout=timeout)
File "d:\Python27\lib\site-packages\sleekxmpp\stanza\iq.py", line 235, in send
raise IqError(result)
IqError
ERROR service-unavailable:
WARNING You should catch IqError exceptions
DEBUG Event triggered: presence
DEBUG Event triggered: presence_available
DEBUG Event triggered: presence
DEBUG Event triggered: presence_available
DEBUG Event triggered: presence
DEBUG Event triggered: presence_available
DEBUG Event triggered: got_online
DEBUG Event triggered: changed_status
DEBUG Event triggered: got_online
DEBUG Event triggered: changed_status
DEBUG Event triggered: changed_status