【发布时间】:2018-03-06 13:55:12
【问题描述】:
python 2.x 代码
sdata = StringIO.StringIO(c.data)
python 3.x 代码
sdata = io.StringIO(c.data)
完整代码
def downloadCSV(c, d):
filename = c.getFilename(d)
reqstr = c.getReqStr(d)
print(("Downloading %s ..." % (filename)))
if c.getResponse(reqstr) == -1:
return -1
sdata = io.StringIO(c.data)
z = zipfile.ZipFile(sdata)
错误:
Traceback (most recent call last):
File "xxx.py", line 166, in <module>
main(sys.argv[1:])
File "xxxx.py", line 158, in main
getMonth(c, args[1], args[2])
File "xxxx.py", line 133, in getMonth
if downloadCSV(c, d) > -1:
File "xxxx.py", line 73, in downloadCSV
sdata = io.StringIO(c.data)
TypeError: initial_value must be str or None, not bytes
3.x python 版本正确导入,sdata 的转换应该在这里自动发生?为什么会出现上述错误,以及在 python3.x 中纠正此错误的方法是什么。尝试了此论坛中发布的其他答案,但在这种情况下似乎没有任何效果。
【问题讨论】:
标签: python python-3.x io