python request api
时间: 2023-10-20 22:11:18 浏览: 89
Python requests module can be used to interact with APIs. Here is an example of making a GET request to an API using requests:
```python
import requests
response = requests.get('https://api.example.com/data')
data = response.json()
print(data)
```
This code sends a GET request to the API endpoint `https://api.example.com/data` and stores the response in the variable `response`. The `json()` method of the response object is used to convert the response data to a Python object (in this case, a dictionary) and store it in the variable `data`. Finally, the response data is printed to the console.
Note that you may need to include additional headers or parameters in your request depending on the specific API you are working with. Consult the API documentation for details.
阅读全文