在xmlrpc上与supervisord交谈

Mar*_*cin 0 python xml-rpc xmlrpclib supervisord

我正在尝试与supervisorxmlrpc 交谈.基于supervisorctl(尤其是这一行),我有以下内容,它似乎应该工作,并且确实它可以工作,只要它足够连接以从服务器接收错误:

#socketpath is the full path to the socket, which exists
# None and None are the default username and password in the supervisorctl options
In [12]: proxy = xmlrpclib.ServerProxy('http://127.0.0.1', transport=supervisor.xmlrpc.SupervisorTransport(None, None, serverurl='unix://'+socketpath))

In [13]: proxy.supervisor.getState()
Run Code Online (Sandbox Code Playgroud)

导致此错误:

---------------------------------------------------------------------------
ProtocolError                             Traceback (most recent call last)
/home/marcintustin/webapps/django/oneclickcosvirt/oneclickcos/<ipython-input-13-646258924bc2> in <module>()
----> 1 proxy.supervisor.getState()

/usr/local/lib/python2.7/xmlrpclib.pyc in __call__(self, *args)
   1222         return _Method(self.__send, "%s.%s" % (self.__name, name))
   1223     def __call__(self, *args):
-> 1224         return self.__send(self.__name, args)
   1225
   1226 ##


/usr/local/lib/python2.7/xmlrpclib.pyc in __request(self, methodname, params)
   1576             self.__handler,
   1577             request,
-> 1578             verbose=self.__verbose
   1579             )
   1580

/home/marcintustin/webapps/django/oneclickcosvirt/lib/python2.7/site-packages/supervisor/xmlrpc.pyc in request(self, host, handler, request_body, verbose)
    469                                           r.status,
    470                                           r.reason,
--> 471                                           '' )
    472         data = r.read()
    473         p, u = self.getparser()

ProtocolError: <ProtocolError for 127.0.0.1/RPC2: 401 Unauthorized>
Run Code Online (Sandbox Code Playgroud)

这是以下unix_http_server部分supervisord.conf:

[unix_http_server]
file=/home/marcintustin/webapps/django/oneclickcosvirt/tmp/supervisor.sock   ; (the path to the socket file)
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))
Run Code Online (Sandbox Code Playgroud)

所以,应该没有身份验证问题.

看起来我的代码在所有重要方面与相同的代码相同supervisorctl,但supervisorctl实际上是有效的.我究竟做错了什么?

lar*_*sks 7

您的代码看起来非常正确.我正在使用Python 2.7运行Supervisor 3.0,并给出以下内容:

import supervisor.xmlrpc
import xmlrpclib

p = xmlrpclib.ServerProxy('http://127.0.0.1',
        transport=supervisor.xmlrpc.SupervisorTransport(
            None, None,
            'unix:///home/lars/lib/supervisor/tmp/supervisor.sock'))

print p.supervisor.getState()
Run Code Online (Sandbox Code Playgroud)

我明白了:

{'statename': 'RUNNING', 'statecode': 1}
Run Code Online (Sandbox Code Playgroud)

您确定正在运行的Supervisor实例正在使用您认为的配置文件吗?如果你supervisord在调试模式下运行,你看到了连接怎么办?