问题描述
我将 SOAPpy 用于soap wsdl 服务.我正在关注这个 toturail.我的代码如下
I am using SOAPpy for soap wsdl services. I am following this toturail. My code is as follow
from SOAPpy import WSDL
wsdlfile = 'http://track.tcs.com.pk/trackingaccount/track.asmx?WSDL'
server = WSDL.Proxy(wsdlfile)
我在代码的最后一行收到此错误
I am getting this error on the last line of my code
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/adil/Code/mezino/RoyalTag/royalenv/local/lib/python2.7/site-packages/SOAPpy/WSDL.py", line 85, in __init__
self.wsdl = reader.loadFromString(str(wsdlsource))
File "/home/adil/Code/mezino/RoyalTag/royalenv/local/lib/python2.7/site-packages/wstools/WSDLTools.py", line 52, in loadFromString
return self.loadFromStream(StringIO(data))
TypeError: initial_value must be unicode or None, not str
我尝试使用
wsdlFile = unicode('http://track.tcs.com.pk/trackingaccount/track.asmx?WSDL, "utf-8")
但仍然有同样的错误.这里缺少什么?
but still having same error. What is missing here ?
推荐答案
我刚刚遇到了这个问题,因为一些非常旧的 2.7 代码由于 TLS 更新而不再有效.更新到最新版本的 Python 2 后,我最终遇到了这个问题.
I just ran into this problem with some very old 2.7 code that no longer worked due to the TLS update. After updating to the most recent version of Python 2 I ended up getting this issue.
我只能通过设置一个新的虚拟环境来解决这个问题,然后修改该虚拟环境中的 wstools 包以使用 BytesIO 而不是 StringIO.
I was only able to fix this by setting up a new virtual environment, then modifying the wstools package in that virtual environment to use BytesIO instead of StringIO.
替换所有必需的 StringIO 实例.例如:
Replace every required instance of StringIO. For example:
# WSDLTools.py
...
from IO import BytesIO
...
return self.loadFromStream(BytesIO(data))
不理想,但有效.比将所有内容迁移到 Python 3 更容易...
Not ideal, but it worked. Easier than migrating everything to Python 3...
这篇关于类型错误:initial_value 必须是 unicode 或 None,而不是 str,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!