Currently I'm running a basic example of django-graphqljwt from the documentation page. https://django-graphql-jwt.domake.io/en/latest/quickstart.html
import graphene
import graphql_jwt
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(mutation=Mutation)
However if I run the tokenAuth
mutation it throws me the below error in the GraphiQL
interface. Note that if I enter incorrect credentials it throws an "Please enter valid credentials
" instead of the below.
{
"errors": [
{
"message": "'str' object has no attribute 'decode'",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"tokenAuth"
]
}
],
"data": {
"tokenAuth": null
}
}
I found this as an open issue on github for the django-graphql-jwt
package and was able to resolve it by resorting to the 1.7.0
version of PyJWT
. Currently installed was version 2.0
https://github.com/flavors/django-graphql-jwt/issues/241
I'm using the django-graphql-jwt==0.2.1
without this problem. Apparently, the problem is related to the new version of django-graphql-jwt
which is 0.3.0
by now. Or, as you mentioned, you could bound the PyJWT
to 1.7.0
.
The solution is using these bounded packages in your requirements.txt
file as follows:
django-graphql-jwt==0.3.0
PyJWT==1.7.0
Or
django-graphql-jwt==0.2.1
I faced a similar issue, this was apparently because PyJWT==2.3.0
was not compatible with django-graphql-jwt
as Dipanshu mentioned in his answer, It worked after downgrading PyJWT==2.3.0
to PyJWT==1.7.0
.
Check if the PyJWT package's version in your virtual environment is greater than 2.0.0 using the below pip command
pip show PyJWT
If it is greater than 2.0.0, use the below pip command to downgrade the package in your virtual environment
pip install --upgrade PyJWT==1.7.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With