json - Web2py 将 CSV 文件作为服务参数传递
问题描述
我现在正在为 web2py 编写一个网络服务。我想将 CSV 文件作为 Web 服务的参数传递并读取 Web 服务中的 CSV。我的问题是,当我尝试传递 CSV 时,出现错误:
<class 'NameError'> name 'basestring' is not defined
Version
web2py™ Version 2.18.5-stable+timestamp.2019.04.08.04.22.03
Python Python 3.6.8: /bin/python3 (prefix: /usr)
Traceback
Traceback (most recent call last):
File "/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/web2py/applications/testwebservice/controllers/default.py", line 83, in <module>
File "/home/ff/web2py/gluon/globals.py", line 421, in <lambda>
self._caller = lambda f: f()
File "/web2py/applications/testwebservice/controllers/default.py", line 20, in index
schaar = webservice.schaar(csv_reader_object)
File "/web2py/gluon/contrib/simplejsonrpc.py", line 112, in <lambda>
return lambda *args, **vars: self.call(attr, *args, **vars)
File "/web2py/gluon/contrib/simplejsonrpc.py", line 144, in call
self.error.get('data', None))
File "/web2py/gluon/contrib/simplejsonrpc.py", line 38, in __init__
if isinstance(data, basestring):
NameError: name 'basestring' is not defined
这是我的网络服务代码:
@service.json
@service.jsonrpc
@service.jsonrpc2
def schaar(csv_reader_object):
csvlist = csv.reader(csv_reader_object, delimiter=',')
csv= list()
headers = csvlist[0]
for i,e in enumerate(csvlist):
if i == 0:
continue
row_dict=dict()
for i2, e2 in enumerate(e):
row_dict[headers[i2]] = e2 if (e2 != None or e2 != "") else None
csv.append(row_dict)
return (csv)
希望您能够帮助我。我已经尝试将二进制文件转换为字符串,但它以某种方式失败了。我已经尝试过BytesIO
andStringIO
了。
我期待着您的回答。
问候费边
解决方案
中存在一个错误gluon.contrib.simplejsonrpc
,该错误已得到修复。只需在 2.18.5 之后升级到 web2py 的任何版本,它应该可以工作(相反,你不会再遇到那个特定的错误,尽管有问题的代码实际上是在JSONRPCError
类中,表明你的代码的其他部分已经引发了例外)。
推荐阅读
- c - Strtok 返回错误数据
- unix - 如何以编程方式查找当前登录的用户 ID?
- flutter - Flutter GestureDetector ListView
- amazon-web-services - ECS使用桥接网络模式无法上网
- identityserver4 - 中央和商店系统之间的无缝 SSO
- qt - QML:使用多个 .qrc 文件时的设计视图
- javascript - 将时间格式 2019-01-21 05:05:11.000000 转换为 1548060780546
- javascript - Javascript点击事件ClientX和clientY值
- data-modeling - Datomic 新手问题 - 当一个事实发生变化时对相关事实进行建模
- c - 执行 dll 时的当前工作目录