API 端点返回 500 服务器错误 - 回溯返回属性错误
API endpoint returning 500 server error - traceback returning attribute error
我有一个 Python API,其中三个端点托管在 Azure 上。其中一个端点上周开始返回服务器错误。我检查了平台,所以那里一切正常。
我检查了日志,发现对于这个端点,traceback returns 这一行在末尾
File ".\app\models.py", line 280, in json
return {'entity': otherentity.name, 'details': self.details, 'entity_id': otherentity.id,
AttributeError: 'NoneType' object has no attribute 'name'
这是标准输出和标准错误:
StdOut:
StdErr: D:\home\site\wwwroot\env\Lib\site-
packages\flask_cache\jinja2ext.py:33: ExtDeprecationWarning: Importing
flask.ext.cache is deprecated, use flask_cache instead.
from flask.ext.cache import make_template_fragment_key
ErrorCode Access is denied.
(0x5)
第 280 行引用的代码块是 class 的一部分。这是区块:
def json(self, entityid):
otherentity = self.entity_1 if entityid == self.entity_id2 else self.entity_2
return {'entity': otherentity.name, 'details': self.details, 'entity_id': otherentity.id,
'id': self.id}
这个应用程序有点像扔给我,所以我是调试方面的新手,据我所知,问题在于调用 .name 因为它不存在?另外,不确定 flask_cache 被弃用是否与此问题有关。
我发现 flask_cache 不再维护,我应该改用 flask-caching。
关于如何继续修复此服务器错误的任何想法?我不确定为什么使用相同模型的其他两个端点有效,但这个却不行。
解决方案是在后端使用 if/else 语句验证代码。通过前端接受的用户输入导致连接失败,该修复解决了该问题。
下一步是将输入验证添加到前端以避免将来出现问题。感谢所有查看此内容并提供帮助的人。
我有一个 Python API,其中三个端点托管在 Azure 上。其中一个端点上周开始返回服务器错误。我检查了平台,所以那里一切正常。
我检查了日志,发现对于这个端点,traceback returns 这一行在末尾
File ".\app\models.py", line 280, in json
return {'entity': otherentity.name, 'details': self.details, 'entity_id': otherentity.id,
AttributeError: 'NoneType' object has no attribute 'name'
这是标准输出和标准错误:
StdOut:
StdErr: D:\home\site\wwwroot\env\Lib\site-
packages\flask_cache\jinja2ext.py:33: ExtDeprecationWarning: Importing
flask.ext.cache is deprecated, use flask_cache instead.
from flask.ext.cache import make_template_fragment_key
ErrorCode Access is denied.
(0x5)
第 280 行引用的代码块是 class 的一部分。这是区块:
def json(self, entityid):
otherentity = self.entity_1 if entityid == self.entity_id2 else self.entity_2
return {'entity': otherentity.name, 'details': self.details, 'entity_id': otherentity.id,
'id': self.id}
这个应用程序有点像扔给我,所以我是调试方面的新手,据我所知,问题在于调用 .name 因为它不存在?另外,不确定 flask_cache 被弃用是否与此问题有关。
我发现 flask_cache 不再维护,我应该改用 flask-caching。
关于如何继续修复此服务器错误的任何想法?我不确定为什么使用相同模型的其他两个端点有效,但这个却不行。
解决方案是在后端使用 if/else 语句验证代码。通过前端接受的用户输入导致连接失败,该修复解决了该问题。
下一步是将输入验证添加到前端以避免将来出现问题。感谢所有查看此内容并提供帮助的人。