Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 461
Adil Malik Avatar asked Sep 27 '16 09:09

Adil Malik


1 Answers

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...

like image 76
Mathew Griffin Avatar answered Oct 19 '22 22:10

Mathew Griffin