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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

捕獲 SSL 問題的請求除外

捕獲 SSL 問題的請求除外

侃侃爾雅 2022-05-24 16:31:16
當我發(fā)送 HEAD 請求以expired.badssl.com測試腳本將如何響應時,我收到以下錯誤:HTTPSConnectionPool(host='expired.badssl.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))我可以專門捕捉到,SSLError以便我知道這是一個糟糕的 SSL 嗎?我需要將此部分分配給except: CERTIFICATE_VERIFY_FAILEDfrom[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)我的請求:host = "https://expired.badssl.com/"timeout = 5try:    r = requests.head(host, headers=headers, timeout=timeout)    try:        print ('Status', r.status_code)        print ('Headers', r.headers)    except NameError:        print("Undefined variable")except requests.exceptions.Timeout:    print ('Timeout...')except requests.exceptions.TooManyRedirects:    print ('Bad URL...')except requests.exceptions.RequestException as e:    print (e)
查看完整描述

2 回答

?
PIPIONE

TA貢獻1829條經(jīng)驗 獲得超9個贊

您可以通過異常參數(shù)獲取它:


import requests


try:

    r = requests.head("https://expired.badssl.com/", timeout=5)


    try:

        print ('Status', r.status_code)

        print ('Headers', r.headers)


    except NameError:

        print("Undefined variable")


except requests.exceptions.SSLError as ssl_error:

    print(ssl_error)

    inner_exception = ssl_error.args[0]

    inner_ssl_error = inner_exception.reason.args[0]

    print(type(inner_ssl_error))

    for key, value in vars(inner_ssl_error).items():

        print(key, '=', value)

    # or just inner_ssl_error.reason etc.


查看完整回答
反對 回復 2022-05-24
?
蕪湖不蕪

TA貢獻1796條經(jīng)驗 獲得超7個贊

測試下面的代碼


import requests 


host = "https://expired.badssl.com/";

timeout = 5

try:

    r = requests.head(host)



    try:

        print ('Status', r.status_code)

        print ('Headers', r.headers)


    except NameError:

        print("Undefined variable")

except requests.exceptions.Timeout:

    print ('Timeout...')

except requests.exceptions.TooManyRedirects:

    print ('Bad URL...')

except requests.exceptions.SSLError:

    print('certificate verify failed')

except requests.exceptions.RequestException as e:

    print (e)

或者


import requests

class check_link:

  def check_broken_link(self,data):

    try:

      r = requests.head(data)                 

      try:

                print ('Status', r.status_code)

                print ('Headers', r.headers)


      except NameError:

          return ("UNDEFINED")


    except requests.exceptions.SSLError:

        return "CERTIFICATE_VERIFY_FAILED"


qc=check_link()

result =qc.check_broken_link('https://expired.badssl.com/')

print(result)


查看完整回答
反對 回復 2022-05-24
  • 2 回答
  • 0 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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