"from flask_smorest import Blueprint\n使用flask-smorest==0.26.0版本编写代码\n@blp.route("/")\nclass UserAPIView(JwtView):\n\t@blp.response(UserNameSchema,200)\n\tdef get(self):\n\t\t"""根据 Token 查询用户名"""\n\t\treturn user_service.get_username()\n使用flask-smorest==0.26.0版本报错\n\tdescription = http.HTTPStatus(int(status_code)).phrase\nTypeError: int() argument must be a string, a bytes-like object or a real number, not 'SchemaMeta'\n怎么修改呢"\n根据报错信息,错误发生在http.HTTPStatus(int(status_code)).phrase这一行。根据代码,status_code应该是一个整数类型的变量,但是报错信息显示status_code的类型是SchemaMeta。\n\n这个问题可能是由于http.HTTPStatus期望一个整数类型的参数,但是传入了类型错误的status_code导致的。\n\n要解决这个问题,可以检查blp.response装饰器中的status_code参数的来源。确保status_code是一个整数类型的变量,例如:\n\npython\n@blp.response(UserNameSchema, 200) # 确保 200 是一个整数\ndef get(self):\n\t\"\"\"根据 Token 查询用户名\"\"\"\n\treturn user_service.get_username()\n\n\n如果status_code是从别处获取的,可以使用int()函数将其转换为整数,例如:\n\npython\nstatus_code = int(status_code)\n@blp.response(UserNameSchema, status_code)\ndef get(self):\n\t\"\"\"根据 Token 查询用户名\"\"\"\n\treturn user_service.get_username()\n\n\n请确保status_code是一个有效的整数值,否则可能会引发其他类型错误。

Flask-Smorest 0.26.0 版本报错:TypeError: int() argument must be a string, a bytes-like object or a real number, not 'SchemaMeta'

原文地址: https://www.cveoy.top/t/topic/p0Mi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录