Locate the encode call in the traceback and confirm it has no algorithm argument. Expected: a call shaped like jwt.encode(payload, key) with nothing naming an algorithm.

Check what algorithm the receiving service or your own decode call expects. Expected: one named algorithm, for example HS256 or RS256, that both sides agree on.

Add that algorithm to the encode call, for example jwt.encode(payload, key, algorithm='HS256'). Expected: the call now names exactly one algorithm.

Confirm the key type matches the algorithm: a shared secret for HS256, a private key in PEM format for RS256. Expected: no key format error on the next run.

Run the encode again and inspect the resulting token header by decoding it without verification in a local test. Expected: the header alg value matches the algorithm you passed.

Run a full round trip, encode then decode with the matching public key or secret and the same algorithms list. Expected: decode returns the original claims with no error.