jupyter-tabnine
jupyter-tabnine copied to clipboard
TypeError in handler.py:self.write(response)
Traceback (most recent call last):
File "/home/lz/code/git/invest/2020-08-05-options/.env-new/lib/python3.8/site-packages/tornado/web.py", line 1703, in _execute
result = await result
File "/home/lz/code/git/invest/2020-08-05-options/.env-new/lib/python3.8/site-packages/jupyter_tabnine/handler.py", line 14, in get
self.write(response)
File "/home/lz/code/git/invest/2020-08-05-options/.env-new/lib/python3.8/site-packages/tornado/web.py", line 834, in write
raise TypeError(message)
TypeError: write() only accepts bytes, unicode, and dict objects
If I understand correctly, the following code tries to call self.write(json_object):
@web.authenticated
async def get(self):
url_params = self.request.uri
request_data = unquote(url_params[url_params.index('=')+1:])
response = self.tabnine.request(request_data)
self.write(response)
However, not all JSON objects are supported by Tornado.RequestHandler.write, and tabnine may return NULL according to its documentation, in which case the code will error out.
Possible fix:
self.write(json.dumps(response))
Hi @htfy96 , thanks for your feedback. I can't reproduce this error. Could you please git clone the latest code and change to self.write(json.dumps(response)) and test it? In the JavaScript code, I already handled string response.
refer to https://github.com/wenmin-wu/jupyter-tabnine/blob/master/src/jupyter_tabnine/static/main.js#L121