【发布时间】:2015-09-29 13:25:38
【问题描述】:
我正在使用请求将 python 客户端写入 Web 服务 (REST)
我想提出,除非用户输入了错误的凭据
我有以下代码块
try:
ret=self.req_session.get(URL)
if (ret.status_code == 401):
raise Authexecption("Improper credentials")
else:
ret.raise_for_status()
except Authexecption:
logging.error("Unable to authenticate. Please check you credentails")
except requests.exceptions.HTTPError:
logging.error("Issue with communicating with Web-Services. The HTTP response is " + str(ret.status_code))
except requests.exceptions.Timeout:
logging.error("Time out while connecting to the Web-Service..")
这里的想法是,我将为身份验证问题提出一个自定义错误消息,并为所有其他问题(5xx、404 等)提出一个通用错误消息。
执行此操作时出现以下错误
except Authexecption:
NameError: global name 'Authexecption' is not defined
我对python很陌生,正在努力学习,我该如何解决这个问题?
-提前致谢
【问题讨论】:
-
嗯,你定义
Authexecption了吗?您的意思是不是Authexception(拼写正确)?
标签: python python-2.7 exception