API端点返回500服务器错误 - 回溯返回属性错误

问题描述 投票:-1回答:1

我有一个Python API,在Azure上托管了三个端点。其中一个端点上周开始返回服务器错误。我检查了平台,所以一切都很好。

我检查了日志,发现对于这个端点,回溯在最后返回这一行

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和std错误:

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行引用的代码块是类的一部分。这是块:

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。

有关如何继续修复此服务器错误的任何想法?我不确定为什么使用相同模型的其他两个端点工作但不是这个。

python json azure flask http-error
1个回答
0
投票

解决方案是在后端使用if / else语句验证代码。通过前端接受的用户输入导致连接失败,并且该修复纠正了该问题。

下一步是向前端添加输入验证以避免将来出现问题。感谢所有检查过这个并帮助过的人。

© www.soinside.com 2019 - 2024. All rights reserved.