简体   繁体   English

错误:TypeError:ColumnClause 类型的对象不是 JSON 可序列化的 Python3

[英]ERROR: TypeError: Object of type ColumnClause is not JSON serializable Python3

Hi i'm getting this error.嗨,我收到此错误。 TypeError: Object of type ColumnClause is not JSON serializable. TypeError: ColumnClause 类型的对象不是 JSON 可序列化的。

Whole thing:整件事:

    [2020-10-26 22:17:58,448] ERROR in app: Exception on /all-user [GET]
Traceback (most recent call last):
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\ryand\Desktop\mealplansfree\main-api\api.py", line 36, in decorated
    return f(*args, **kwargs)
  File "C:\Users\ryand\Desktop\mealplansfree\main-api\api.py", line 59, in get_all_users
    return jsonify({'users' : output})
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\json\__init__.py", line 370, in jsonify
    dumps(data, indent=indent, separators=separators) + "\n",
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\json\__init__.py", line 211, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "c:\users\ryand\appdata\local\programs\python\python38-32\lib\json\__init__.py", line 234, in dumps
    return cls(
  File "c:\users\ryand\appdata\local\programs\python\python38-32\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "c:\users\ryand\appdata\local\programs\python\python38-32\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "c:\users\ryand\.virtualenvs\main-api-ucgvpon1\lib\site-packages\flask\json\__init__.py", line 100, in default
    return _json.JSONEncoder.default(self, o)
  File "c:\users\ryand\appdata\local\programs\python\python38-32\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ColumnClause is not JSON serializable

Here is the code for the above.这是上面的代码。

  @app.route('/all-user', methods=['GET'])
@application_required
def get_all_users():

    users = User.query.all()

    output = []

    for user in users:
        user_data = {}
        user_data['user_id'] = user.user_id
        user_data['full_name'] = user.full_name
        user_data['username'] = user.username
        user_data['password'] = user.password
        user_data['admin'] = user.admin
        output.append(user_data)

    return jsonify({'users' : output})

here is the secret key check这是密钥检查

def application_required(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        token = None

        if 'x-access-key' in request.headers:
            token = request.headers['x-access-key']

        if not token:
            return jsonify({'message' : 'ERROR x-access-key missing or incorrect.'}), 401

        if token == app.config['SECRET_KEY']:
            return f(*args, **kwargs)
        else:
            return jsonify({'message' : 'ERROR x-access-key missing or incorrect.'}), 401

    return decorated

If anyone knows whats going on or could guide me through whats going on and how to debug these that would be great!如果有人知道发生了什么或者可以指导我了解正在发生的事情以及如何调试这些,那就太好了!

I found the answer here: SQLAlchemy warning: column won't be part of the declarative mapping我在这里找到了答案: SQLAlchemy 警告:列不会成为声明性映射的一部分

I had missed in my User model in the username it was a lowercase c and not upper case C. This fixed the error and is now working.我在我的 User 模型中的用户名中遗漏了它是小写的 c 而不是大写的 C。这修复了错误,现在正在工作。 Thanks!谢谢!

The cause can be data type.原因可能是数据类型。 You are using lot of data types.您正在使用大量数据类型。 Try to reduce data type changes.尝试减少数据类型更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:TypeError 类型的对象不是 JSON 可序列化的 Python - TypeError: Object of type TypeError is not JSON serializable Python Python 错误:TypeError:'Timestamp' 类型的对象不是 JSON 可序列化的' - Python error : TypeError: Object of type 'Timestamp' is not JSON serializable' Python/Flask - “TypeError”类型的对象不是 JSON 可序列化的 - Python/Flask - Object of type "TypeError' is not JSON serializable 如何使用python3中的pyShp修复“TypeError:类型'字节'的对象不是JSON可序列化的” - How to fix “TypeError: Object of type 'bytes' is not JSON serializable” using pyShp in python3 Python TypeError:“ ndarray”类型的对象不可JSON序列化 - Python TypeError: Object of type 'ndarray' is not JSON serializable Python - Flask - TypeError 类型的 Object 不是 JSON 可序列化的 - Python - Flask - Object of type TypeError is not JSON serializable Python TypeError:“字节”类型的对象不是 JSON 可序列化的 - Python TypeError: Object of type 'bytes' is not JSON serializable “TypeError”类型的对象不是 JSON 可序列化的 - Object of type 'TypeError' is not JSON serializable JSON 和 Python 的密码术:TypeError:Object 字节类型不是 Z0ECD11C148A23BBD7A2 - JSON and Cryptography With Python: TypeError: Object of type bytes is not JSON serializable TypeError:Tensor 类型的对象不是 JSON 可序列化的 - Pytorch 中的 json 错误 - TypeError: Object of type Tensor is not JSON serializable - dict to json error in Pytorch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM