第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Tornado中的`send_error`, `write_error`和`raise HTTPError`有什么區(qū)別?

Tornado中的`send_error`, `write_error`和`raise HTTPError`有什么區(qū)別?

牧羊人nacy 2019-05-25 13:37:45
RT,官方文檔看的不是很懂:RequestHandler.send_error(status_code=500,kwargs)**SendsthegivenHTTPerrorcodetothebrowser.Ifflush()hasalreadybeencalled,itisnotpossibletosendanerror,sothismethodwillsimplyterminatetheresponse.Ifoutputhasbeenwrittenbutnotyetflushed,itwillbediscardedandreplacedwiththeerrorpage.Overridewrite_error()tocustomizetheerrorpagethatisreturned.Additionalkeywordargumentsarepassedthroughtowrite_error.RequestHandler.write_error(status_code,kwargs)**Overridetoimplementcustomerrorpages.write_errormaycallwrite,render,set_header,etctoproduceoutputasusual.Ifthiserrorwascausedbyanuncaughtexception(includingHTTPError),anexc_infotriplewillbeavailableaskwargs["exc_info"].Notethatthisexceptionmaynotbethe“current”exceptionforpurposesofmethodslikesys.exc_info()ortraceback.format_exc.我理解的是send_error調(diào)用了write_error,所以寫自定義錯(cuò)誤頁面的時(shí)候要自己實(shí)現(xiàn)write_error方法,拋出錯(cuò)誤的時(shí)候使用send_error。那么又該在什么時(shí)候使用rasietornado.web.HTTPError呢?
查看完整描述

2 回答

?
當(dāng)年話下

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊

HTTPError一般是用tornado訪問某個(gè)url,然后這個(gè)url不存在,或者返回一個(gè)錯(cuò)誤碼的時(shí)候用到的。
fromtornado.httpclientimportHTTPClient,HTTPError
http_client=HTTPClient()
try:
response=http_client.fetch(url,method='GET',request_timeout=120)
exceptHTTPErrorashttp_error:
printhttp_error
exceptExceptionase:
printe
finally:
http_client.close()
                            
查看完整回答
反對 回復(fù) 2019-05-25
?
忽然笑

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊

send_error是Torando發(fā)送錯(cuò)誤狀態(tài)碼到瀏覽器,而write_error是對自定義的錯(cuò)誤頁面進(jìn)行重寫,是2個(gè)不同的操作。
                            
查看完整回答
反對 回復(fù) 2019-05-25
  • 2 回答
  • 0 關(guān)注
  • 925 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號