Thanks to visit codestin.com
Credit goes to github.com

Skip to content

example/faq/health_check_server.py bug: connection.respond expects str not bytes #1546

@TrevinAvery

Description

@TrevinAvery

I ran the example for "How do I implement a health check?" and got the error AttributeError: 'bytes' object has no attribute 'encode'. Did you mean: 'decode'?

I took a look and found that ServerConnection.respond expects the second parameter text to be a str. It then passes it to ServerProtocol.reject, which also expects a string and calls text.encode() to convert it to bytes.

The example passes a bytes string to ServerConnection.respond, causing this issue.

Fix

Change

connection.respond(HTTPStatus.OK, b"OK\n")

to

connection.respond(HTTPStatus.OK, "OK\n")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions