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

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

使用flask python issue獲取響應(yīng)status_code

使用flask python issue獲取響應(yīng)status_code

白板的微信 2021-11-16 14:32:30
我想使用 Flask python 獲得監(jiān)控服務(wù)的響應(yīng) HTTP status_code。我的代碼:from flask import Flask, request, url_for, redirect, render_template, flash, Response, abortimport requestsres = requests.get('https://192.168.1.100:8000/token?api=API',verify=False)app = Flask(__name__)print(res.url) # your.domain/test/3/3print(res.status_code) # 200@app.route('/services')def check_services():   if request.method == "GET" or request.method == "POST":         if res.status_code == '201':                result =  'Sucess HTTP.Status_code 201 - Service TOKEN is working fine [OK]'               return render_template('services.html'), 201#              result = '401 -- Service TOKEN is working fine - parameter is not correct'        else:#                abort(401)                 return render_template('services401.html'),401  但我的代碼沒有正常工作。我的預(yù)期結(jié)果,它將由單獨(dú)的 HTTP 狀態(tài)代碼返回:201 或 401 或 500,無(wú)論我在if條件中定義什么。任何幫助表示贊賞?。?!
查看完整描述

1 回答

?
翻閱古今

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

狀態(tài)代碼是int,不是str。因此,請(qǐng)檢查201,而不是'201'。你的代碼應(yīng)該是:


if request.method == "GET" or request.method == "POST": 

    if res.status_code == 201:

        # do what you want here

詳情請(qǐng)見下文。


>>> import requests

>>> r = requests.get('https://httpbin.org/get')

>>> r.status_code

200

>>> type(r.status_code)

<class 'int'>


查看完整回答
反對(duì) 回復(fù) 2021-11-16
  • 1 回答
  • 0 關(guān)注
  • 394 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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