我有這個功能,其中包含嘗試和除外。我在獲取異常代碼時遇到問題。AttributeError爲例外代碼
我寫了這樣的代碼第一:
def _runQuery(self, query, request=None)
try:
//request codes here
except Exception, e:
messages.error(
request,
'Error connecting to OFX server. URL: {0} ERROR: {1} {2}'.format(
self.account.bank.ofx_url, e.code, e.msg))
return ''
我例外,總是給我,電子對象有沒有屬性「代碼」一個AttributeError。所以我認爲有時Exception沒有代碼呈現或它是空的。我再次重寫我的密碼,這是最新的。
except Exception, e:
code = ""
if e.code:
code = e.code
messages.error(
request,
'Error connecting to OFX server. URL: {0} ERROR: {1} {2}'.format(
self.account.bank.ofx_url, code, e.msg))
現在,它給了我不同的錯誤 - AttributeError的: 'SSLError' 對象有沒有屬性 '代碼'
如何解決這一問題?並獲得沒有這個問題的代碼?