gpt4 book ai didi

Django 和 SOAP 水 : 'NoneType' object has no attribute 'str' in suds

转载 作者:行者123 更新时间:2023-12-02 11:56:08 25 4
gpt4 key购买 nike

我在 Django(1.3、python 2.7)中使用 Suds 时遇到一些问题。

当我在脚本中使用 suds 检索数据时,它可以工作;但是如果我将**完全相同的**代码放入 django View 中,则会收到错误:

'NoneType' object has no attribute 'str' in suds

我的代码很简单:

client = Client(WSDL_URL, location=LOCATION_URL, cache=None)
client.service.getRooms({'type':'AVAILABLE'})

以及完整的回溯:

File "/Users/lundi/Irusia/WWW/rooms/views.py", line 45, in available
client.service.getRooms({'type':'AVAILABLE'})
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 595, in invoke
soapenv = binding.get_message(self.method, args, kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/bindings/binding.py", line 120, in get_message
content = self.bodycontent(method, args, kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/bindings/document.py", line 63, in bodycontent
p = self.mkparam(method, pd, value)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/bindings/document.py", line 105, in mkparam
return Binding.mkparam(self, method, pdef, object)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/bindings/binding.py", line 287, in mkparam
return marshaller.process(content)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/mx/core.py", line 62, in process
self.append(document, content)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/mx/core.py", line 73, in append
log.debug('appending parent:\n%s\ncontent:\n%s', parent, content)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1120, in debug
self._log(DEBUG, msg, args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1250, in _log
self.handle(record)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1260, in handle
self.callHandlers(record)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1300, in callHandlers
hdlr.handle(record)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 744, in handle
self.emit(record)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py", line 791, in emit
msg = self.format(record) + '\000'
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 719, in format
return fmt.format(record)
File "/Users/lundi/Irusia/WWW/base/log.py", line 22, in format
s = '%s [%s] %s: %s' % (dt, record.name, record.levelname, record.getMessage())
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 328, in getMessage
msg = msg % self.args
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/sax/document.py", line 58, in __str__
return unicode(self).encode('utf-8')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/sax/document.py", line 61, in __unicode__
return self.str()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/sax/document.py", line 48, in str
s.append(self.root().str())
AttributeError: 'NoneType' object has no attribute 'str'

我不知道为什么使用 Django 时会出现此错误。

我认为这个人有同样的问题:AttributeError: 'NoneType' object has no attribute 'str' in suds

所以如果有人有想法,

谢谢。

最佳答案

该 bug 存在于泡沫中,但通常是无声的。然而,当使用 django-debug-toolbar 时,该错误就会暴露出来,因为日志记录面板显示了所有已记录的消息。

我创建了一个修补版本的肥皂水来解决这个问题:https://github.com/bradleyayers/suds-htj

关于 Django 和 SOAP 水 : 'NoneType' object has no attribute 'str' in suds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9664705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com