TypeError: initial_value must be unicode or None, not str,
Asked Answered
C

1

6

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 ?

Carrizales answered 27/9, 2016 at 9:23 Comment(1)
Works for me; at a guess, the url did not resolve at the time the question was asked.Experiment
P
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...

Purvey answered 14/12, 2018 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.