Token cannot be created ('str' has no attribute 'decode')
See original GitHub issueI’ve recently started to incorporate GraphQL into one of my existing projects. Installed django-graphql-jwt according to the documentation but whenever I run the below, I get the following error:
mutation { tokenAuth( username: "dummy", password: "dummydummy" ) { token } }
{ "errors": [ { "message": "'str' object has no attribute 'decode'", "locations": [ { "line": 2, "column": 3 } ], "path": [ "tokenAuth" ] } ], "data": { "tokenAuth": null } }
I’ve searched almost everywhere but I cannot track down what the issue and as far as I can see it should work?
Relevant pieces of code: Settings.py
"SCHEMA": "blackbook.schema.schema",
"MIDDLEWARE": [
"graphql_jwt.middleware.JSONWebTokenMiddleware",
"graphene_django.debug.DjangoDebugMiddleware",
],
}
Blackbook.schema
import graphql_jwt
from .api import user
class Query(user.Query, graphene.ObjectType):
pass
class Mutation(graphene.ObjectType):
token_auth = graphql_jwt.ObtainJSONWebToken.Field()
verify_token = graphql_jwt.Verify.Field()
refresh_token = graphql_jwt.Refresh.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)```
Issue Analytics
- State:
- Created 3 years ago
- Reactions:15
- Comments:13
Top Results From Across the Web
AttributeError: 'str' object has no attribute 'decode' python error
If you are using PyJwt module, then there is no need to decode the token. jwt.encode({some_dict}) returns the token you need.
Read more >AttributeError: 'str' object has no attribute 'decode' | bobbyhadz
The Python "AttributeError: 'str' object has no attribute 'decode'" occurs when we call the decode() method on a string that has already been...
Read more >How To Solve 'Str' Object Has No Attribute 'Decode' Error
The 'str' object has no attribute 'decode' error occurs when you try to decode an object that is already decoded. So, you can...
Read more >Attributeerror: 'str' object has no attribute 'decode' ( Solved )
The solution to this error is that you don't have to decode the string. It's because if you are using the python 3....
Read more >Solve the attributeerror str object has no attribute decode error
This attribute error occurs because you are trying to call the decode() function on a Python string object, which is by default already...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Further investigation learned that this is a change in pyjwt, where as from version 2.0.0 the token returned will not be a sequences of bytes but a string. Solved for now by pinning the version of pyjwt to <2.
Another option to fix this issue, install PyJWT==1.7.0