向我的 REST API 发送 POST 请求时出现此错误。有谁知道这是什么意思?我正在使用烧瓶 mysql 而不是 SQL alchemy
- 检测到“C:\Users\User-PC\Desktop\Python API\models.py”的变化,重新加载
- 用 stat 重启
- 调试器处于活动状态!
- 调试器 PIN:114-398-217
- 在http://127.0.0.1:5000/上运行(按 CTRL+C 退出){'username': 'ah', 'password': 'oh'} 127.0.0.1 - - [26/Apr/2021 16: 54:36] “←[35m←[1mPOST /api/auth/login HTTP/1.1←[0m”” 500 - 回溯(最近一次通话最后):
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_restful\__init__.py", line 272, in error_router
return original_handler(e)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\_compat.py", line 38, in reraise
raise value.with_traceback(tb)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_restful\__init__.py", line 272, in error_router
return original_handler(e)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\_compat.py", line 38, in reraise
raise value.with_traceback(tb)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_restful\__init__.py", line 468, in wrapper
resp = resource(*args, **kwargs)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_restful\__init__.py", line 583, in dispatch_request
resp = meth(*args, **kwargs)
File "C:\Users\User-PC\Desktop\Python API\resources.py", line 22, in post
user = User.fetch_userid_from_db(post_data['username'])
File "C:\Users\User-PC\Desktop\Python API\models.py", line 24, in fetch_userid_from_db
cur = mysql.connection.cursor()
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_mysqldb\__init__.py", line 94, in connection
ctx.mysql_db = self.connect
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_mysqldb\__init__.py", line 43, in connect
if current_app.config['MYSQL_HOST']:
KeyError: 'MYSQL_HOST'
{'username': 'ah', 'password': 'oh'}
127.0.0.1 - - [26/Apr/2021 16:55:18] "←[35m←[1mPOST /api/auth/login HTTP/1.1←[0m" 500 -
Traceback (most recent call last):
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_restful\__init__.py", line 272, in error_router
return original_handler(e)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\_compat.py", line 38, in reraise
raise value.with_traceback(tb)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_restful\__init__.py", line 272, in error_router
return original_handler(e)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\_compat.py", line 38, in reraise
raise value.with_traceback(tb)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_restful\__init__.py", line 468, in wrapper
resp = resource(*args, **kwargs)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask\views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_restful\__init__.py", line 583, in dispatch_request
resp = meth(*args, **kwargs)
File "C:\Users\User-PC\Desktop\Python API\resources.py", line 22, in post
user = User.fetch_userid_from_db(post_data['username'])
File "C:\Users\User-PC\Desktop\Python API\models.py", line 24, in fetch_userid_from_db
cur = mysql.connection.cursor()
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_mysqldb\__init__.py", line 94, in connection
ctx.mysql_db = self.connect
File "C:\Users\User-PC\AppData\Local\Programs\Python\Python39\Lib\site-packages\flask_mysqldb\__init__.py", line 43, in connect
if current_app.config['MYSQL_HOST']:
KeyError: 'MYSQL_HOST'