Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Token cannot be created ('str' has no attribute 'decode')

See original GitHub issue

I’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:

    "SCHEMA": "blackbook.schema.schema",


import graphql_jwt

from .api import user

class Query(user.Query, graphene.ObjectType):

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:closed
  • Created 3 years ago
  • Reactions:15
  • Comments:13

github_iconTop GitHub Comments

bsiebenscommented, Dec 16, 2020

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.

gtg7784commented, Jan 12, 2021

Another option to fix this issue, install PyJWT==1.7.0

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found