xxxxxxxxxx
import requests
# Define the API endpoint URL
url = 'https://api.example.com/data'
try:
# Make the API request
response = requests.get(url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Extract the data from the response
data = response.json()
# Process the data as needed
# ...
else:
print('Error:', response.status_code)
except requests.exceptions.RequestException as e:
print('Error:', e)
xxxxxxxxxx
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/hello', methods=['GET'])
def hello():
return jsonify(message='Hello, World!')
if __name__ == '__main__':
app.run()
xxxxxxxxxx
response = requests.get("https://api.open-notify.org/this-api-doesnt-exist")