【问题标题】:xmpppy create user accountxmpppy 创建用户帐户
【发布时间】:2013-04-08 08:57:43
【问题描述】:

我搜索了如何在 Python 中创建 Openfire 帐户,发现以下answer

我尝试了Joe Hildebrand 给出的代码,并在运行 Openfire 3.8.1 的机器上运行代码

python register.py foo@localhost bar

创建一个帐户。

但是,我得到“错误!”消息。

有什么我错过的吗?

编辑
删除, debug[]后 再试一次,我收到以下消息:

Invalid debugflag given: always  
Invalid debugflag given: nodebuilder  
DEBUG:  
DEBUG: Debug created for /usr/local/lib/python2.7/dist-packages/xmpppy-0.5.0rc1-py2.7.egg/xmpp/client.py  
DEBUG:  flags defined: always,nodebuilder  
DEBUG: socket       start Plugging <xmpp.transports.TCPsocket instance at 0x19991b8> into <xmpp.client.Client instance at 0x1988fc8>  
DEBUG: socket       warn  An error occurred while looking up _xmpp-client._tcp.localhost  
DEBUG: socket       start Successfully connected to remote host ('localhost', 5222)  
DEBUG: dispatcher   start Plugging <xmpp.dispatcher.Dispatcher instance at 0x199b2d8> into <xmpp.client.Client instance at 0x1988fc8>  
DEBUG: dispatcher   info  Registering namespace "unknown"  
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(unknown)  
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(unknown)  
DEBUG: dispatcher   info  Registering namespace "http://etherx.jabber.org/streams"  
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)  
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)  
DEBUG: dispatcher   info  Registering namespace "jabber:client"  
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(jabber:client)  
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(jabber:client)  
DEBUG: dispatcher   info  Registering protocol "iq" as <class 'xmpp.protocol.Iq'>(jabber:client)  
DEBUG: dispatcher   info  Registering protocol "presence" as <class 'xmpp.protocol.Presence'>(jabber:client)  
DEBUG: dispatcher   info  Registering protocol "message" as <class 'xmpp.protocol.Message'>(jabber:client)  
DEBUG: dispatcher   info  Registering handler <bound method Dispatcher.streamErrorHandler of <xmpp.dispatcher.Dispatcher instance at 0x199b2d8>> for "error" type-> ns->(http://etherx.jabber.org/streams)  
DEBUG: dispatcher   warn  Registering protocol "error" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)  
DEBUG: socket       sent  <?xml version='1.0'?>  
  <stream:stream xmlns="jabber:client" to="localhost" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" >  
DEBUG: socket       got   <?xml version='1.0' encoding='UTF-8'?>  
  <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="mymachine" id="1724a327" xml:lang="en" version="1.0">  
DEBUG: socket       got   <stream:features>  
  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">  
  </starttls>  
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">  
  <mechanism>DIGEST-MD5</mechanism>  
  <mechanism>PLAIN</mechanism>  
  <mechanism>ANONYMOUS</mechanism>  
  <mechanism>CRAM-MD5</mechanism>  
  </mechanisms>  
  <compression xmlns="http://jabber.org/features/compress">  
  <method>zlib</method>  
  </compression>  
  <auth xmlns="http://jabber.org/features/iq-auth"/>  
  <register xmlns="http://jabber.org/features/iq-register"/>  
  </stream:features>  
DEBUG: dispatcher   warn  Unknown stanza: features  
DEBUG: dispatcher   ok    Dispatching unknown stanza with type-> props->[u'urn:ietf:params:xml:ns:xmpp-tls', u'urn:ietf:params:xml:ns:xmpp-sasl', u'http://jabber.org/features/compress', u'http://jabber.org/features/iq-auth', u'http://jabber.org/features/iq-register'] id->None  
DEBUG: tls          start Plugging <xmpp.transports.TLS instance at 0x199b908> into <xmpp.client.Client instance at 0x1988fc8>  
DEBUG: tls          ok    TLS supported by remote server. Requesting TLS start.  
DEBUG: dispatcher   info  Registering handler <bound method TLS.StartTLSHandler of <xmpp.transports.TLS instance at 0x199b908>> for "proceed" type-> ns->(urn:ietf:params:xml:ns:xmpp-tls)  
DEBUG: dispatcher   warn  Registering namespace "urn:ietf:params:xml:ns:xmpp-tls"  
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)  
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)  
DEBUG: dispatcher   warn  Registering protocol "proceed" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)  
DEBUG: dispatcher   info  Registering handler <bound method TLS.StartTLSHandler of <xmpp.transports.TLS instance at 0x199b908>> for "failure" type-> ns->(urn:ietf:params:xml:ns:xmpp-tls)  
DEBUG: dispatcher   warn  Registering protocol "failure" as <class 'xmpp.protocol.Protocol'>(urn:ietf:params:xml:ns:xmpp-tls)  
DEBUG: socket       sent  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>  
DEBUG: socket       got   <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>  
DEBUG: dispatcher   ok    Got urn:ietf:params:xml:ns:xmpp-tls/proceed stanza  
DEBUG: dispatcher   ok    Dispatching proceed stanza with type-> props->[] id->None  
DEBUG: tls          ok    Got starttls proceed response. Switching to TLS/SSL...  
DEBUG: dispatcher   stop  Plugging <xmpp.dispatcher.Dispatcher instance at 0x199b2d8> out of <xmpp.client.Client instance at 0x1988fc8>.  
DEBUG: dispatcher   start Plugging <xmpp.dispatcher.Dispatcher instance at 0x19a4560> into <xmpp.client.Client instance at 0x1988fc8>  
DEBUG: dispatcher   info  Registering namespace "unknown"  
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(unknown)  
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(unknown)  
DEBUG: dispatcher   info  Registering namespace "http://etherx.jabber.org/streams"  
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)  
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)  
DEBUG: dispatcher   info  Registering namespace "jabber:client"  
DEBUG: dispatcher   info  Registering protocol "unknown" as <class 'xmpp.protocol.Protocol'>(jabber:client)  
DEBUG: dispatcher   info  Registering protocol "default" as <class 'xmpp.protocol.Protocol'>(jabber:client)  
DEBUG: dispatcher   info  Registering protocol "iq" as <class 'xmpp.protocol.Iq'>(jabber:client)  
DEBUG: dispatcher   info  Registering protocol "presence" as <class 'xmpp.protocol.Presence'>(jabber:client)  
DEBUG: dispatcher   info  Registering protocol "message" as <class 'xmpp.protocol.Message'>(jabber:client)  
DEBUG: dispatcher   info  Registering handler <bound method Dispatcher.streamErrorHandler of <xmpp.dispatcher.Dispatcher instance at 0x19a4560>> for "error" type-> ns->(http://etherx.jabber.org/streams)  
DEBUG: dispatcher   warn  Registering protocol "error" as <class 'xmpp.protocol.Protocol'>(http://etherx.jabber.org/streams)  
DEBUG: socket       sent  <?xml version='1.0'?>  
  <stream:stream xmlns="jabber:client" to="localhost" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" >  
DEBUG: socket       sent  <iq to="localhost" type="get" id="1">  
  <query xmlns="jabber:iq:register" />  
  </iq>  
DEBUG: dispatcher   wait  Waiting for ID:1 with timeout 25...  
DEBUG: socket       got   <?xml version='1.0' encoding='UTF-8'?>  
  <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="mymachine" id="1724a327" xml:lang="en" version="1.0">  
  <stream:features>  
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">  
  <mechanism>DIGEST-MD5</mechanism>  
  <mechanism>PLAIN</mechanism>  
  <mechanism>ANONYMOUS</mechanism>  
  <mechanism>CRAM-MD5</mechanism>  
  </mechanisms>  
  <compression xmlns="http://jabber.org/features/compress">  
  <method>zlib</method>  
  </compression>  
  <auth xmlns="http://jabber.org/features/iq-auth"/>  
  <register xmlns="http://jabber.org/features/iq-register"/>  
  </stream:features>  
DEBUG: dispatcher   warn  Unknown stanza: features  
DEBUG: dispatcher   ok    Dispatching unknown stanza with type-> props->[u'urn:ietf:params:xml:ns:xmpp-sasl', u'http://jabber.org/features/compress', u'http://jabber.org/features/iq-auth', u'http://jabber.org/features/iq-register'] id->None  
DEBUG: socket       got   <iq type="error" id="1" from="localhost" to="mymachine/1724a327">  
  <query xmlns="jabber:iq:register"/>  
  <error code="400" type="modify">  
  <bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>  
  </error>  
  </iq>  
DEBUG: dispatcher   ok    Got jabber:client/iq stanza  
DEBUG: dispatcher   ok    Dispatching iq stanza with type->error props->[u'jabber:iq:register', u'jabber:client'] id->1  
DEBUG: dispatcher   ok    Expected stanza arrived!  
DEBUG: socket       sent  <iq to="localhost" type="set" id="2">  
  <query xmlns="jabber:iq:register">  
  <username>foo</username>  
  <password>bar</password>  
  </query>  
  </iq>
DEBUG: dispatcher   wait  Waiting for ID:2 with timeout 25...  
DEBUG: socket       got   <iq type="error" id="2" from="localhost" to="mymachine/1724a327">  
  <query xmlns="jabber:iq:register">  
  <username>foo</username>  
  <password>bar</password>  
  </query>  
  <error code="400" type="modify">  
  <bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>  
  </error>  
  </iq>  
DEBUG: dispatcher   ok    Got jabber:client/iq stanza  
DEBUG: dispatcher   ok    Dispatching iq stanza with type->error props->[u'jabber:iq:register', u'jabber:client'] id->2  
DEBUG: dispatcher   ok    Expected stanza arrived!  
Error!  

【问题讨论】:

  • 从 Client 构造函数中删除 , debug=[] 部分,如果不清楚答案是什么,请在此处发布协议。
  • 我删除了`, debug=[] 并再次尝试。我已通过编辑将错误消息发布到我的问题中。协议指的是什么?

标签: python xmpp


【解决方案1】:

假设您正在连接,最常见的错误是用户已经存在,或者服务器不支持注册。

但是,您上面的错误跟踪显示您收到错误400,而不是403409403 表示注册已关闭,409 表示用户已经存在。

通过发送到无效的 JID,我能够在 OpenFire 3.8.1 中复制您的问题。当您配置 OpenFire 时,您指定了一个域。该域必须位于您在 Python 脚本的命令行中指定的 JID 中。比如我在配置的时候指定了“localhost”。当我使用“foo@mymachine”而不是“foo@localhost”时,出现 400 错误。如果您需要域与机器名称不同(很常见),则使用 DNS SRV 记录(请参阅RFC 6120, section 3.2),或更改 Python 代码,以便此行:

cli=xmpp.Client(jid.getDomain())

看起来像这样:

cli=xmpp.Client("hostname")

后者是一个快速的技巧,但应该可以让你启动并运行。

【讨论】:

  • " 是否有错别字,例如我在配置时指定了"localhost"。当我使用"foo@mymachine" 而不是"foo@localhosthost" 时,出现400 错误? foo@localhosthost 是否意味着 foo@localhost?
  • 如果我要使用DNS SRV记录,是否意味着我应该在运行Openfire的服务器上安装DNS服务器,例如bind9?
  • 是的,localhosthost 是一个错字。固定。
  • 您不一定需要自己的 DNS 服务器。您可以将记录放入您感兴趣的域的 DNS 服务器中。但是,如果您没有访问权限,一个快速的方法是安装 dnsmasq (thekelleys.org.uk/dnsmasq/doc.html) 作为本地转发器。 DNSmasq 很容易添加新记录,包括 SRV。确保将测试机器的 DNS 指向运行 DNSmasq 的位置(可能是 127.0.0.1)。
  • 很抱歉我对DNS服务器不是很熟悉。是否“您可以将记录放入您感兴趣的域的 DNS 服务器中。”意思是把DNS记录放到上层DNS服务器,比如我的ISP?
猜你喜欢
  • 2010-10-19
  • 2020-10-15
  • 1970-01-01
  • 2011-04-13
  • 1970-01-01
  • 2013-06-29
  • 1970-01-01
  • 2011-01-29
  • 2013-02-16
相关资源
最近更新 更多