一个接口如果响应时间太长,但是我们不想等太长时间,此时就可以用timeout设置超时时间,如果在指定时间内,接口未响应,此时就会抛出:requests.exceptions.ConnectTimeout的异常
#!usr/bin/env python
#-*- coding:utf-8 -*-
"""
@author:Administrator
@file: requests_post.py
@time: 2018/10/13
"""
import requests
import json
url = "https://tieba.baidu.com/f"
#将要传的参数以key value的形式定义在data字典中
data = {"ie":"utf-8","kw":"李毅"}
r = requests.get(url=url,
params=data,
timeout=0.01
)