【问题标题】:TypeError: initial_value must be unicode or None, not str,TypeError:initial_value 必须是 unicode 或 None,而不是 str,
【发布时间】:2023-03-09 01:30:02
【问题描述】:

我将 SOAPpy 用于肥皂 wsdl 服务。我正在关注这个toturail。我的代码如下

from SOAPpy import WSDL
wsdlfile = 'http://track.tcs.com.pk/trackingaccount/track.asmx?WSDL'
server = WSDL.Proxy(wsdlfile)

我在代码的最后一行收到此错误

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

我尝试使用

将字符串转换为 utf
wsdlFile = unicode('http://track.tcs.com.pk/trackingaccount/track.asmx?WSDL, "utf-8")

但仍然有同样的错误。这里缺少什么?

【问题讨论】:

  • 为我工作;猜测一下,在提出问题时,该 url 没有解析。

标签: python python-2.7 soap unicode soappy


【解决方案1】:

我刚刚遇到了一些非常旧的 2.7 代码由于 TLS 更新而不再工作的问题。在更新到最新版本的 Python 2 后,我最终遇到了这个问题。

我只能通过设置一个新的虚拟环境来解决这个问题,然后修改该虚拟环境中的 wstools 包以使用 BytesIO 而不是 StringIO。

替换每个必需的 StringIO 实例。例如:

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

不理想,但它有效。比将所有内容迁移到 Python 3 更容易...

【讨论】:

    猜你喜欢
    • 2018-11-25
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 2021-09-09
    • 1970-01-01
    • 2020-07-11
    相关资源
    最近更新 更多