python requests max_retries set the maximum number of retries

Unfortunately, requests.post or requests.get do not support this max_retries parameter. So if you add it hard, you will get an error:
TypeError: request() got an unexpected keyword argument 'max_retries'

solution

Method 1: Use the global default configuration

requests.DEFAULT_RETRIES = 3

Method 2: Do it yourself with a while loop

i = 0
while i < 3:
    try:
        response = requests.get(url, timeout=3)
    except:
        i += 1

Welcome to follow

Artificial intelligence technology analysis
Artificial intelligence machine learning Deep learning
AI artificial intelligence three elements: data, computing power and algorithm
Computer vision (CV) task introduction: classification, detection, segmentation, super-resolution, key point recognition, image generation, metric learning

The official account continues to update original content, welcome to subscribe.

AI artificial intelligence and big data
Alt

Guess you like

Origin blog.csdn.net/guanxs/article/details/126891634