| # Generic code to make api requests using python requests library: frame | |
| import requests | |
| from urllib.parse import urljoin, urlencode, urlparse, urlunparse | |
| # Define the base URL | |
| BASE_URL = 'https://b4b8-134-28-45-21.ngrok-free.app/' | |
| #BASE_URL = 'http://127.0.0.1:5000/' | |
| def make_get_request(endpoint,params): | |
| try: | |
| # Make a GET request to the endpoint | |
| response = requests.get( | |
| url = f'{BASE_URL}{endpoint}', | |
| params=params, | |
| verify=True | |
| ) | |
| print(response.url) | |
| # Check if the response is successful | |
| except requests.RequestException as e: | |
| print(f"Request failed: {e}") | |
| return None | |
| return response | |
| # Make a POST request to the endpoint | |
| def make_post_request(endpoint,params,data=None): | |
| if data is None: | |
| return | |
| # Make a POST request to the endpoint | |
| response = requests.post( | |
| url=BASE_URL + endpoint, | |
| params=params, | |
| data=data, | |
| verify=True | |
| ) | |
| # Check if the response is successful | |
| # Return the error | |
| return response | |