
    fik                         d Z ddlZddlZddlmZmZ ddlZddlmZ 	 	 	 	 	 dd	e	d
ede
de
dedeeef         dej        fdZdS )u0   
Date: 2025/12/31
Desc: HTTP 请求工具函数
    N)DictTuple)HTTPAdapter            ?g      ?g      ?urlparamstimeoutmax_retries
base_delayrandom_delay_rangereturnc                    d}t          |          D ]}	 t          j                    5 }t          dd          }	|                    d|	           |                    d|	           |                    | ||          }
|
                                 |
cddd           c S # 1 swxY w Y   # t          j        t          f$ r@}|}||dz
  k     r+|d|z  z  t          j
        | z   }t          j        |           Y d}~d}~ww xY w|)u?  
    带重试机制的 HTTP GET 请求
    :param url: 请求 URL
    :type url: str
    :param params: 请求参数
    :type params: dict
    :param timeout: 超时时间（秒）
    :type timeout: int
    :param max_retries: 最大重试次数
    :type max_retries: int
    :param base_delay: 基础延迟时间（秒），用于指数退避
    :type base_delay: float
    :param random_delay_range: 随机延迟范围（秒）
    :type random_delay_range: tuple
    :return: Response 对象
    :rtype: requests.Response
    :raises: 最后一次请求的异常
    N   )pool_connectionspool_maxsizezhttp://zhttps://)r   r      )rangerequestsSessionr   mountgetraise_for_statusRequestException
ValueErrorrandomuniformtimesleep)r
   r   r   r   r   r   last_exceptionattemptsessionadapterresponseedelays                @/usr/local/lib/python3.11/dist-packages/akshare/utils/request.pyrequest_with_retryr*      su   4 N%% " "	"!##  w%qqIIIi111j'222";;s67;KK))+++                                      ):6 	" 	" 	"Nq(("aj1FNDV4WW
5!!!	" s;   B.A+B"B."B&	&B.)B&	*B..D6C??D)Nr   r   r   r	   )__doc__r   r    typingr   r   r   requests.adaptersr   strintfloatResponser*        r)   <module>r4      s    
            ) ) ) ) ) )
 .81 1	11 1 	1
 1 eUl+1 1 1 1 1 1 1r3   