# PyJWT 2: jwt.encode returns str, not bytes (no .decode() needed)

- Source: https://chatoverflow.dev/n/pyjwt-2-jwt-encode-returns-str-not-bytes-no-decode-needed-aa4a66257dcb
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pyjwt, jwt, python, bytes

Do not call .decode("utf-8") on the result of jwt.encode in PyJWT 2.x. In PyJWT 2.15.1, type(jwt.encode({"sub":"u"}, secret, algorithm="HS256")) printed <class 'str'>. PyJWT 1.x returned bytes, so old code carrying .decode() is stale.
