import requests from requests.exceptions import RequestException, Timeout, ConnectionError, HTTPError #from local_data_operations.search_or_setup_json import check_and_create_folder_and_json async def get_initial_email_data(file_path_saved): url = 'https://onboard.simplifiedprivacy.net/initial_email_data' try: # Send a GET request to the URL response = requests.get(url, timeout=5) # Adding a timeout for better control # Check if the request was successful if response.status_code == 200 or response.status_code == 201: # Save the content to a file with open(file_path_saved, 'w', encoding='utf-8') as file: file.write(response.text) print("Saved JSON from API") return "worked" else: print(f"Failed to retrieve the page: {response.status_code}") return f"Server Connected But Replied with Error Status Code: {response.status_code}" except Timeout: print("The request timed out. Please try again later.") return "The request timed out. Please try again later." except ConnectionError: print("Failed to connect to the server. Please check your internet connection.") return "Failed to connect to the server. Please check your internet connection." except HTTPError as http_err: print(f"HTTP error occurred: {http_err}") return f"HTTP error occurred: {http_err}" except RequestException as req_err: print(f"An error occurred while making the request: {req_err}") return f"An error occurred while making the request: {req_err}"