1

我正在尝试使用 python 从 XMLRPC Web 服务中使用服务。远程 Web 服务器需要身份验证和 ssl 验证。为了做到这一点,我实现了一个 xmlrpc 客户端,使用xmlrpc.client如下:

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()由于响应格式吗?有什么解决办法?

4

0 回答 0