Web2py 将 CSV 文件作为服务的参数传递



我现在正在为web2py编写一个Web服务。我想传递一个 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)

希望你能帮助我。我已经尝试将二进制文件转换为字符串,但不知何故失败了。我已经尝试了BytesIOStringIO

我期待你的回答。

问候法比安

gluon.contrib.simplejsonrpc中有一个错误,后来得到了修复。只需升级到 2.18.5 之后的任何版本的 web2py,它应该可以工作(相反,您不会再收到该特定错误,尽管有问题的代码实际上在JSONRPCError类中,表明您的代码的其他部分引发了异常(。

最新更新