TypeError: initial_value must be unicode or None, not str,

谁都会走 提交于 2019-12-07 03:07:19

问题


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

I tried to convert the string into utf using

wsdlFile = unicode('http://track.tcs.com.pk/trackingaccount/track.asmx?WSDL, "utf-8")

but still having same error. What is missing here ?


回答1:


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.

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.

Replace every required instance of StringIO. For example:

# WSDLTools.py
...
from IO import BytesIO
...
return self.loadFromStream(BytesIO(data))

Not ideal, but it worked. Easier than migrating everything to Python 3...



来源:https://stackoverflow.com/questions/39720919/typeerror-initial-value-must-be-unicode-or-none-not-str

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