weibeu / Flask-Discord

Discord OAuth2 extension for Flask. An Easier implementation of "Log In With Discord".
https://flask-discord.readthedocs.io/en/latest/
MIT License
182 stars 47 forks source link

TypeError: Expected a string value #54

Closed jvherck closed 3 years ago

jvherck commented 3 years ago

The code below always gives me the error TypeError: Expected a string value. Something in the flask-discord module itself is causing this error because I'm just doing exactly what the documentation says.

@app.route('/login')
def login():
    return auth.create_session()

Error:

[2021-10-30 09:39:27,372] ERROR in app: Exception on /login [GET]
Traceback (most recent call last):
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\app.py", line 2070, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1515, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "C:\Users\janva\PycharmProjects\webtest\app.py", line 25, in login
    return auth.create_session()
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\flask_discord\client.py", line 99, in create_session
    state = jwt.encode(data, current_app.config["SECRET_KEY"], algorithm="HS256")
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\jwt\api_jwt.py", line 63, in encode
    return api_jws.encode(json_payload, key, algorithm, headers, json_encoder)
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\jwt\api_jws.py", line 110, in encode
    key = alg_obj.prepare_key(key)
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\jwt\algorithms.py", line 180, in prepare_key
    key = force_bytes(key)
  File "C:\Users\janva\AppData\Local\Programs\Python\Python39\lib\site-packages\jwt\utils.py", line 21, in force_bytes
    raise TypeError("Expected a string value")
TypeError: Expected a string value
127.0.0.1 - - [30/Oct/2021 09:39:27] "GET /login HTTP/1.1" 500 -
weibeu commented 3 years ago

Can you check and make sure that you're setting Flask SECRET_KEY in your application config. You can look into Flask documentation to check on how to set secret key in your Flask application.

jvherck commented 3 years ago

Ohh I didn't set any secret key, I forgot about that. Thank you very much!