写一段python代码处理request
时间: 2023-06-05 11:06:33 浏览: 98
python网络爬虫代码资料
4星 · 用户满意度95%
Sure, here's some sample Python code for handling a request:
```
import requests
# URL endpoint to send the request to
url = "https://api.example.com/endpoint"
# Set up the headers for the request
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
}
# Data to send in the request body (if needed)
data = {
"param1": "value1",
"param2": "value2"
}
# Send the request
response = requests.post(url, headers=headers, json=data)
# Check the response status code and content
if response.status_code == 200:
print(response.json())
else:
print("Error sending request:", response.status_code)
```
Hope this helps! Let me know if you have any other questions.
阅读全文