requests详细参数说明

-1. timeout:请求超时时间,单位为秒。

 

```python

import requests

 

response = requests.get(url, timeout=5) # 设置5秒超时

```

 

2. verify:请求SSL证书验证。

 

```python

import requests

 

response = requests.get(url, verify=False) # 不进行证书验证

```

 

3. cert:SSL证书路径

 

```python

import requests

 

response = requests.get(url, cert=('path/to/cert.pem', 'path/to/key.pem'))

```

 

4. stream:是否以流方式获取响应内容。

 

```python

import requests

 

response = requests.get(url, stream=True) # 以流方式获取响应内容

```

 

5. headers:请求头

 

```python

import requests

 

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}

response = requests.get(url, headers=headers)

```

 

6. cookies:Cookie值

 

```python

import requests

 

cookies = {'name': 'value'}

response = requests.get(url, cookies=cookies)

```

 

7. proxies:代理服务器地址

 

```python

import requests

 

proxies = {'http': 'http://127.0.0.1:8888', 'https': 'https://127.0.0.1:8888'}

response = requests.get(url, proxies=proxies)

```

 

8. auth:HTTP认证信息

 

```python

import requests

 

auth = ('username', 'password')

response = requests.get(url, auth=auth)

```

 

9. params:请求参数

 

```python

import requests

 

params = {'key1': 'value1', 'key2': 'value2'}

response = requests.get(url, params=params)

```

 

10. json:请求参数为JSON格式

 

```python

import requests

import json

 

data = {'key1': 'value1', 'key2': 'value2'}

json_data = json.dumps(data)

response = requests.post(url, json=json_data)

```

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值