Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError in handler.py:self.write(response) #52

Open
htfy96 opened this issue Sep 3, 2020 · 1 comment
Open

TypeError in handler.py:self.write(response) #52

htfy96 opened this issue Sep 3, 2020 · 1 comment

Comments

@htfy96
Copy link

htfy96 commented Sep 3, 2020

    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))
@wenmin-wu
Copy link
Contributor

wenmin-wu commented Sep 5, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants