Suds Error: BadStatusLine in httplib

删除回忆录丶 提交于 2019-11-29 00:42:35

That means there is a problem on the server side which causes the HTTP server to reply with some junk instead of an ordinary 'HTTP/1.1 200 OK' (or similar) line. You can't fix that.

I had the same problem. To troubleshoot the problem, I turned on full suds logging:

logging.basicConfig(level=logging.INFO)
logging.getLogger("suds.client").setLevel(logging.DEBUG)
logging.getLogger("suds.transport").setLevel(logging.DEBUG)
logging.getLogger("suds.xsd.schema").setLevel(logging.DEBUG)
logging.getLogger("suds.wsdl").setLevel(logging.DEBUG)

With the debugging output, I noticed that the error occured when SUDS tried to download http://www.w3.org/2001/xml.xsd (that particular schema was in some way referenced by the service I was trying to call). Turns out that the w3.org server is very overloaded (link, link).

The SUDS Client can be configured to use a cache. I implemented a cache object that returns the contents of two w3.org URLs that SUDS was hitting (you can find the URLs in the log output). I used a browser to fetch the two schemas and save them to disk and then put the contents as string contstants inside a source code file.

from suds.cache import NoCache
from suds.sax.parser import Parser

class StaticSudsCache(NoCache):
    def get(self, id):
        STATIC = {"http://www.w3.org/2001/xml.xsd": XML_XSD,
                "http://www.w3.org/2001/XMLSchema.xsd": XMLSCHEMA_XSD }
        xml_string = STATIC.get(id.name)
        if xml_string:
            p = Parser()
            return p.parse(string=xml_string)

from suds.client import Client
c = Client(service_url, cache=StaticSudsCache())

XML_XSD = """... contents from file ..."""
XMLSCHEMA_XSD = """... contents from file ..."""

The full code including the XML schema content is here.

httplib is a pure python module.. you can have a look at the code for more precise information... BadStatusLine is raised if the status line can’t be parsed as a valid HTTP/1.0 or 1.1 status line. No solution as of now

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!