import time
import requestsdef measure_response_time(api_url):try:start_time = time.time()response = requests.get(api_url, timeout=10) # 设置超时时间为10秒end_time = time.time()response_time = end_time - start_timeprint(f"接口 {api_url} 的响应时间为:{response_time} 秒")except requests.exceptions.RequestException as e:print(f"无法访问接口 {api_url},错误: {e}")if __name__ == '__main__':api_urls = ['http://www.baidu.com','https://chat.qinzhi.xyz/chat/15773192312389']for url in api_urls:measure_response_time(url)
需要安装requests包 pip install requests