XMLRPC客户端中的TypeError

时间:2019-05-15 12:57:02

标签: python python-3.x xml-rpc xmlrpcclient

我试图使用python从XMLRPC Web服务中使用服务。 远程Web服务器需要身份验证和SSL验证。为此,我使用xmlrpc.client实现了一个xmlrpc客户端,如下所示:

class HTTPSDigestAuthTransport:

    def request(self, host, handler, request_body, verbose=0):
        api_url = Setup.get_api_url()
        username = Setup.get_api_username()
        password = Setup.get_api_password()
        h = httplib2.Http()
        if verbose:
            h.debuglevel = 1
        h.add_credentials(username, password)
        h.disable_ssl_certificate_validation = True
        resp, content = h.request("https://" + api_url, "POST", body=request_body,
                              headers={'content-type': 'text/xml'})
        if resp.status != 200:
            raise ProtocolError("https://" + api_url, resp.status, resp.reason, None)
        p, u = getparser(0)
        p.feed(content)


# transport factory instance
transport = HTTPSDigestAuthTransport()

# url composition
url = "https://" + Setup.get_api_username() + ":" + Setup.get_api_password() + "@" + Setup.get_api_url()

# create the proxy
proxy = xmlrpc.client.ServerProxy(url, transport)
res = proxy.do_some_work()

问题是指令res = proxy.do_some_work()产生此错误:

File "/usr/lib/python3.6/xmlrpc/client.py", line 1112, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python3.6/xmlrpc/client.py", line 1455, in __request
if len(response) == 1:

TypeError:类型为'NoneType'的对象没有len()

object of type 'NoneType' has no len()是否使用响应格式?有什么解决方案?

0 个答案:

没有答案