Python API端点返回500服务器错误-回溯返回属性错误
我有一个Python API,其中有三个端点托管在Azure上。其中一个端点上周开始返回服务器错误。我检查了站台,所以那里一切正常 我检查了日志,发现对于这个端点,回溯在末尾返回这一行Python API端点返回500服务器错误-回溯返回属性错误,python,json,azure,flask,http-error,Python,Json,Azure,Flask,Http Error,我有一个Python API,其中有三个端点托管在Azure上。其中一个端点上周开始返回服务器错误。我检查了站台,所以那里一切正常 我检查了日志,发现对于这个端点,回溯在末尾返回这一行 File ".\app\models.py", line 280, in json return {'entity': otherentity.name, 'details': self.details, 'entity_id': otherentity.id, AttributeError: 'NoneTyp
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行引用的代码块是类的一部分。这里是街区:
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_缓存是否与此问题有关
我发现flask_缓存不再维护,我应该改用flask缓存
关于如何继续修复此服务器错误,有什么想法吗?我不知道为什么使用相同模型的其他两个端点可以工作,但这个端点不行。解决方案是用后端的if/else语句验证代码。通过前端接受的用户输入导致连接失败,该修复程序纠正了该问题
下一步是将输入验证添加到前端,以避免将来出现问题。感谢所有检查并提供帮助的人。哦,是不是
otherentity
的值为“none”?这可以解释错误message@Hannu嗯,好的。这很奇怪,因为它在两周前还可以正常工作,没有任何代码更改。如何在本地测试变量?在这方面我是个新手。最简单的方法是将print(otherentity)
放在赋值和return子句之间。如果确实没有,那么检查self.entity变量以了解哪里出了问题。您还可以检查entityid是什么。如果您的entityid与self.entity\u id2
不匹配,您似乎也会将self.entity\u 2
分配给其他实体。也许这是故意的,也许你的意思是相反的?@Hannu,我试试看。我是在那个人离开后进入这个项目的,所以我不确定他们的意图是什么。