Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

python - Suds Error: BadStatusLine in httplib

I am using suds 0.3.6. When creating a suds client, I randomly get an error:

httplib.py, _read_status(), line 355, class httplib.BadStatusLine'

Here is the code used to create the client:

imp = Import('http://www.w3.org/2001/XMLSchema')
imp.filter.add('http://tempuri.org/encodedTypes')
imp.filter.add('http://tempuri.org/')
self.doctor = ImportDoctor(imp)

self.client = Client(self.URL,doctor=self.doctor)

What does this error mean and how can I fix it?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...