import logging
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from urllib3.exceptions import MaxRetryError
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s :%(levelname)s : %(funcName)s - %(message)s')
def make_api_request(url):
s = requests.Session()
retries = Retry(total=6, backoff_factor=1, connect=5, status=3, status_forcelist=[400, 401, 404, 500, 501, 502])
# Prepare the request with Retry
s.mount("https://", HTTPAdapter(max_retries=retries))
s = requests.get(url, proxies=def_proxies)
# Status Code checking
if s.status_code != 200:
logging.error("Warning : Status Code call <> 200: {}".format(s.status_code))
return s.json()
# Request Exception Handling
except MaxRetryError as maxer:
print("Max Retries Error:", maxer)
except requests.exceptions.HTTPError as errh:
print("Http Error:", errh)
except requests.exceptions.ConnectionError as errc:
print("Error Connecting:", errc)
except requests.exceptions.Timeout as errt:
print("Timeout Error:", errt)
except requests.exceptions.RequestException as err:
print("OOps: Something Else", err)
在我的日志中,没有任何信息显示已经执行了重试
我添加了一个maxretryerror来捕获它,但没有在它上面引发任何问题
所以我决定发射wireshark:-(
当我在401上模拟一个错误登录的例子
12 2.917294 192.168.43.85 69.84.209.64 TCP 66 61620 â 443 [SYN] Seq=0 Win=17520 Len=0 MSS=1460 WS=256 SACK_PERM=1
14 2.972088 192.168.43.85 69.84.209.64 TCP 54 61620 â 443 [ACK] Seq=1 Ack=1 Win=17408 Len=0
15 3.168677 192.168.43.85 69.84.209.64 TLSv1.2 571 Client Hello
20 3.314637 192.168.43.85 69.84.209.64 TCP 66 61620 â 443 [ACK] Seq=518 Ack=1337 Win=16128 Len=0 SLE=2673 SRE=4009
22 3.315087 192.168.43.85 69.84.209.64 TCP 54 61620 â 443 [ACK] Seq=518 Ack=4009 Win=17408 Len=0
26 3.316322 192.168.43.85 69.84.209.64 TCP 54 61620 â 443 [ACK] Seq=518 Ack=5619 Win=17408 Len=0
27 3.318149 192.168.43.85 69.84.209.64 TLSv1.2 412 Client Key Exchange, Change Cipher Spec, Encrypted Handshake Message
35 3.475570 192.168.43.85 69.84.209.64 TLSv1.2 363 Application Data
38 3.674813 192.168.43.85 69.84.209.64 TCP 54 61620 â 443 [ACK] Seq=1185 Ack=6179 Win=16896 Len=0
40 3.874986 192.168.43.85 69.84.209.64 TCP 54 61620 â 443 [FIN, ACK] Seq=1185 Ack=6248 Win=16640 Len=0
43 4.034423 192.168.43.85 69.84.209.64 TCP 54 61620 â 443 [ACK] Seq=1186 Ack=6249 Win=16640 Len=0
严格来说,没有执行过任何重审的证据