requests detailed parameter description

-1. timeout: request timeout, in seconds.

 

```python

import requests

 

response = requests.get(url, timeout=5) # Set a timeout of 5 seconds

```

 

2. verify: request SSL certificate verification.

 

```python

import requests

 

response = requests.get(url, verify=False) # No certificate verification

```

 

3. cert: SSL certificate path

 

```python

import requests

 

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

```

 

4. stream: Whether to obtain the response content in a streaming manner.

 

```python

import requests

 

response = requests.get(url, stream=True) # Get the response content in a stream

```

 

5. headers: request header

 

```python

import requests

 

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

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

```

 

6. cookies: cookie value

 

```python

import requests

 

cookies = {'name': 'value'}

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

```

 

7. proxies: proxy server address

 

```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 authentication information

 

```python

import requests

 

auth = ('username', 'password')

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

```

 

9. params: request parameters

 

```python

import requests

 

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

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

```

 

10. json: The request parameter is in JSON format

 

```python

import requests

import json

 

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

json_data = json.dumps(data)

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

```

Guess you like

Origin blog.csdn.net/weixin_59246157/article/details/130779094