Fix #10837 by adding JSON encoding/decoding to the Module API example… (#10845)

This commit is contained in:
Charles Wright 2021-09-17 12:04:37 -05:00 committed by GitHub
parent b4c1af8cea
commit 6b6bb81b23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

1
changelog.d/10845.doc Normal file
View File

@ -0,0 +1 @@
Fix some crashes in the Module API example code, by adding JSON encoding/decoding.

View File

@ -136,9 +136,9 @@ class IsUserEvilResource(Resource):
self.evil_users = config.get("evil_users") or []
def render_GET(self, request: Request):
user = request.args.get(b"user")[0]
user = request.args.get(b"user")[0].decode()
request.setHeader(b"Content-Type", b"application/json")
return json.dumps({"evil": user in self.evil_users})
return json.dumps({"evil": user in self.evil_users}).encode()
class ListSpamChecker: