You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Account到Settings时触发Pydantic 'Field required'错误的问题求助

添加Account到Settings时触发Pydantic 'Field required'错误的问题求助

我最近在尝试把Account类集成到Settings相关逻辑里时,碰到了一个特别费解的Pydantic错误。明明我已经传入了user和pass_两个字段,但系统却提示我缺失字段。更奇怪的是,如果我把Settings里的accounts变量移除,这个错误就直接消失了。

错误信息如下:

Field required [type=missing, input_value={'user': '3EE590j6dB', 'pass_': 'PaDPzEIBjF'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing

我用到的代码片段:

from py3xui.client.client import Client
from py3xui.inbound.bases import JsonStringModel
from pydantic import BaseModel, Field
from typing import List, Optional

# pylint: disable=too-few-public-methods
class SettingsFields:
    """Stores the fields returned by the XUI API for parsing."""

    CLIENTS = "clients"
    DECRYPTION = "decryption"
    FALLBACKS = "fallbacks"

# Define the Account class
class Account(BaseModel):
    user: str
    pass_: str = Field(alias='pass')  # Using alias because 'pass' is a reserved keyword in Python

我实在搞不明白问题出在哪——传入的字典里明明包含了user和pass_,Account类也正确定义了这两个字段(为了避开Python的保留字pass,我给pass_字段设置了alias)。有没有前辈能帮我分析下为什么会触发这个缺失字段的错误?

备注:内容来源于stack exchange,提问作者Ahmed Zaidan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 08:29:29