KeyError: 'oauth_state' - python

Hi I am currently trying to test the code on https://github.com/futurice/whereareyou
I have a problem on the master server side.
The error received
Traceback (most recent call last):
File "/home/arms/.local/lib/python2.7/site-packages/flask/app.py", line 1997, in call
return self.wsgi_app(environ, start_response)
File "/home/arms/.local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/home/arms/.local/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/arms/.local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/home/arms/.local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/arms/.local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/arms/.local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/home/arms/.local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/arms/Project/whereareyou/app.py", line 112, in callback
google = get_google_auth(state=session['oauth_state'])
File "/home/arms/.local/lib/python2.7/site-packages/werkzeug/local.py", line 377, in
getitem = lambda x, i: x._get_current_object()[i]
KeyError: 'oauth_state'
Please help. Thank you.

I was facing the same problem when I was using session in my app with the following link provided by Flask :
http://127.0.0.1:5000/
Solution: It however perfectly works with http://localhost:5000/
Just replace your local IP address(127.0.0.1) with "localhost".

Related

Flask flask_uploads.UploadNotAllowed error

I am using flask to handle image uploads and whenever I upload a jpg, jpeg, or png the program I made is able to handle the upload. However, whenever uploading a .jfif image the program returns the error flask_uploads.UploadNotAllowed. Thanks for any help in advance!
The code the program is having an issue with is:
file_name = photos.save(request.files['photo'])
full traceback:
Traceback (most recent call last):
File
"C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "c:\Users\user\Desktop\OCR - Copy\OCRWebsite\app.py", line 421, in upload
file_name = photos.save(request.files['photo'])
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_uploads.py", line 416, in save
raise UploadNotAllowed()
flask_uploads.UploadNotAllowed
You are probably using the standard IMAGES set:
https://github.com/jugmac00/flask-reuploaded/blob/f05077b085393dbc607c01b8daff1b3a8b2dbf0b/src/flask_uploads/extensions.py#L29
This set does not allow .jfif files.
However, such a set is really only a Python set, so you can create and use your own, or just update the existing one.
IMAGES.update(".jfif")

Dash tutoriel error : Unexpected keyword argument

i'm learning Dash following this tutoriel https://github.com/amyoshino/Dash_Tutorial_Series
the problem is that when i install the project and try to run app.py function i found this error :
Traceback (most recent call last):
File "app.py", line 58, in <module>
dcc.Checklist(
File
"C:\Users\Asus\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\
LocalCache\local-packages\Python38\site-packages\dash\development\base_component.py",
line 42, in wrapper
return func(*args, **kwargs)
File
"C:\Users\Asus\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\
local-packages\Python38\site-packages\dash_core_components\Checklist.py", line 69, in __init__
super(Checklist, self).__init__(**args)
File
"C:\Users\Asus\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\
LocalCache\local-packages\Python38\site-packages\dash\development\base_component.py", line 82, in
__init__
raise TypeError(
TypeError: Unexpected keyword argument `values`
Allowed arguments: className, id, inputClassName, inputStyle, labelClassName, labelStyle,
loading_state, options, persisted_props, persistence, persistence_type, style, value
PS: I have installed all the requirements and libraries needed
when i change values with value the code runs but when i open the localhost another error occur
127.0.0.1 - - [17/Jan/2021 15:53:20] "←[35m←[1mGET /_dash-component-
suites/dash_renderer/dash_renderer.min.js.map?v=1.8.3 HTTP/1.1←[0m" 500 -
Traceback (most recent call last):
File
"C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File
"C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File
"C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1867, in
handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1952, in
full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1821, in
handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1950, in
full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1936, in
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File
"C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\
dash\dash.py", line 393, in serve_component_suites
mimetype = ({
KeyError: 'map'
127.0.0.1 - - [17/Jan/2021 15:53:21] "←[35m←[1mGET /_dash-component-
suites/dash_renderer/dash_renderer.min.js.map?v=1.8.3
HTTP/1.1←[0m" 500 -
Traceback (most recent call last):
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\Asus\AppData\Local\
Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1867, in
handle_exception
reraise(exc_type, exc_value, tb)
File
"C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Asus\AppData\Local\
Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1952, in
full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1821, in
handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1950, in
full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\flask\app.py", line 1936, in
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Asus\AppData\Local\Packages\
PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-
packages\Python38\site-packages\dash\dash.py", line 393, in
serve_component_suites
mimetype = ({
KeyError: 'map'
127.0.0.1 - - [17/Jan/2021 15:53:21] "←[37mGET /favicon.ico HTTP/1.1←[0m" 200 -
That repo contains the error. As the traceback informs you, values is not allowed there, but you can use value. Change it locally and it should resolve the error. Additionally, you could make a pull request to that repo and help the original author(s) by fixing a bug in their code.

Flask doesn't see the static file

Regards, It's been seeing my static files by now. I am using VS Code as an editor. I clicked accidentally debug mode and then it stopped seeing my static files. I started VS Code again but the result hasn't changed. How can I solve this problem? When I open localhost, it shows 127.0.0.1:5000/static/css/main.css but it gives an error when I display the page source and open the css file on the new page.
The error I get in the browser is: TypeError: make_conditional() got an unexpected keyword argument 'accept_ranges'
The error I received in VS Code is as follows:
127.0.0.1 - - [12/Dec/2018 23:17:50] "GET /static/css/main.css HTTP/1.1" 500 -
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python3.6/site-packages/flask/helpers.py", line 976, in send_static_file
cache_timeout=cache_timeout)
File "/usr/local/lib/python3.6/site-packages/flask/helpers.py", line 713, in send_from_directory
return send_file(filename, **options)
File "/usr/local/lib/python3.6/site-packages/flask/helpers.py", line 628, in send_file
complete_length=fsize)
TypeError: make_conditional() got an unexpected keyword argument 'accept_ranges'
According to flask, the required Werkzeug version is Werkzeug >= 0.14 from here

PyGithub, can't get repos from enterprise

I am creating a bot with Spark (chat for enterprise), in Python, I use PyGitHub for the librairy.
So when I write "repos" in my room with the bot he has to send me back the list of my repos.
It works fine with my github personnal account but not with my professionnal account.
If you can explain me why ?
here my code:
def gitTest(self, details, message):
url = "https://enter-prise.com"
token = "abcd"
github = Github(token, base_url=url)
for repo in github.get_organization("org").get_repos():
self.answer(details.roomId, markdown=repo.name)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/mflamant/Documents/bot/CiscoSparkPython/testbotforgithub/main.py", line 44, in Main
bot.isRunnable()
File "/home/mflamant/Documents/bot/CiscoSparkPython/testbotforgithub/utils/Compute.py", line 47, in isRunnable
self.spark(message[0], message[1])
File "/home/mflamant/Documents/bot/CiscoSparkPython/testbotforgithub/testbotforgithub.py", line 33, in spark
return self.answer(details.roomId, markdown=self.gitTest(details, message))
File "/home/mflamant/Documents/bot/CiscoSparkPython/testbotforgithub/testbotforgithub.py", line 56, in gitTest
for repo in github.get_organization(adt).get_repos():
File "/usr/local/lib/python2.7/dist-packages/PyGithub-1.35-py2.7.egg/github/Organization.py", line 539, in get_repos
self.url + "/repos",
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Can you explain me what is wrong with my code ? thank you
If gitTest is an instance method, you need to assign to the attribute self.url, not just to the local variable url. So your method should probably look like this:
def gitTest(self, details, message):
self.url = "https://enter-prise.com"
self.token = "abcd"
github = Github(token, base_url=url)
for repo in github.get_organization("org").get_repos():
self.answer(details.roomId, markdown=repo.name)
This is why you pass in the reference to self as the first argument of any instance method.

Peewee 'Connection already open' in url_value_preprocessor with Flask

What I am trying to do is check the subdomain value passed to the route methods just like explained here
Whenever I access the panel blueprint I receive this error: peewee.OperationalError: Connection already open
This is how I initialize the database in my main app file.
flask_db = FlaskDB(app)
database = flask_db.database
The problematic code seems to be
#panel.url_value_preprocessor
def check_client_and_user(endpoint, values):
client = Client.get(Client.subdomain == values.pop('client'))
The full source code can be found on Gitlab
__init__.py is the main app file. panel/__init__.py has the problematic code. This is the full traceback I receive:
Traceback (most recent call last):
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1610, in full_dispatch_request
rv = self.preprocess_request()
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1831, in preprocess_request
rv = func()
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/playhouse/flask_utils.py", line 171, in connect_db
self.database.connect()
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/peewee.py", line 3679, in connect
raise OperationalError('Connection already open')
peewee.OperationalError: Connection already open
I don't know where the extra connection is coming from. It seems like it is being generated by the Client.select() query.
Edit:
This code here
def get_or_404(client):
app.logger.debug(database.get_tables())
cli = Client.select().where(Client.subdomain == client)
Generates this response
--------------------------------------------------------------------------------
DEBUG in models [/home/marten/Projects/Comp/server/app/panel/models.py:14]:
['client', 'role', 'user', 'userroles']
--------------------------------------------------------------------------------
127.0.0.1 - - [17/Aug/2017 14:57:31] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1610, in full_dispatch_request
rv = self.preprocess_request()
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/flask/app.py", line 1831, in preprocess_request
rv = func()
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/playhouse/flask_utils.py", line 171, in connect_db
self.database.connect()
File "/home/marten/Projects/Comp/server/venv/lib/python3.6/site-packages/peewee.py", line 3679, in connect
raise OperationalError('Connection already open')
peewee.OperationalError: Connection already open
As you can see the database is actually connected, and the client table is available.
Edit 2:
Well, I just found that apparently just database.get_tables() will cause this error. However, that code does fetch all tables from the database...
Does url_value_preprocessor run before the database is initialized? That would be strange since I import the object calling this decorator after initializing the database.

Categories

Resources