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

Inner bug: TypeError: __init__() got an unexpected keyword argument 'escape_forward_slashes' #2740

Closed
1 task done
ArdenL opened this issue Apr 15, 2023 · 2 comments
Closed
1 task done

Comments

@ArdenL
Copy link

ArdenL commented Apr 15, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

i'm not sure if this is a bug, a internal exception occurred when i try to access the inspector page(http://localhost:6457/),

pkgs version:
sanic 23.3.0
sanic-ext 23.3.0
sanic-routing 22.8.0

log:

[ERROR] Exception occurred while handling uri: 'http://localhost:6457/'
Traceback (most recent call last):
  File "handle_request", line 97, in handle_request
    from sanic_ext.extensions.base import Extension  # type: ignore
  File "D:\apps\Anaconda\envs\sanic\lib\site-packages\sanic\worker\inspector.py", line 82, in _info
    return await self._respond(request, self._state_to_json())
  File "D:\apps\Anaconda\envs\sanic\lib\site-packages\sanic\worker\inspector.py", line 86, in _respond
    return json(
  File "D:\apps\Anaconda\envs\sanic\lib\site-packages\sanic\response\convenience.py", line 50, in json
    return JSONResponse(
  File "D:\apps\Anaconda\envs\sanic\lib\site-packages\sanic\response\types.py", line 361, in __init__
    self._encode_body(self._use_dumps(body, **self._use_dumps_kwargs)),
  File "D:\apps\Anaconda\envs\sanic\lib\json\__init__.py", line 234, in dumps
    return cls(
TypeError: __init__() got an unexpected keyword argument 'escape_forward_slashes'

Code snippet

No response

Expected Behavior

No response

How do you run Sanic?

As a script (app.run or Sanic.serve)

Operating System

windows

Sanic Version

Sanic 23.3.0; Routing 22.8.0

Additional context

No response

@ArdenL ArdenL added the bug label Apr 15, 2023
@Tronic
Copy link
Member

Tronic commented Apr 15, 2023

This appears to be a bug in sanic/worker/inspector.py:86 which uses escape_forward_slashes=False argument meant for ujson.dumps() but the Python standard library json.dumps doesn't support that argument. As a workaround, pip install ujson could work, as Sanic should then use that library rather than Python's.

As a more proper fix, I would like to see Sanic always inject that argument to ujson.dumps, and not doing it specifically in inspector code. The built-in json.dumps has no such escaping (equivalent to =False with ujson).

Escaping forward slashes is a retarded feature meant for injecting JSON into HTML script element such that it reads as Javascript and doesn't accidentally contain </script> (in some string literal) and I have no idea why ujson enables it by default but Sanic would be wise to disable it globally, and instead rely on html5tagger's capability to escape script inline content in HTML correctly if that was ever needed.

@ArdenL
Copy link
Author

ArdenL commented Apr 16, 2023

Thanks for you reply, just like you said inject the argument to json.dumps instead of default action is a good idea. Anyway, i use ujson to get what i want. Thank you again.

ahopkins pushed a commit that referenced this issue Jul 5, 2023
@ahopkins ahopkins closed this as completed Jul 5, 2023
moshe742 pushed a commit to moshe742/sanic that referenced this issue Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants