I understand that I have no problem connecting to EA manually by passing the file directly.
I need to fully automate the process so the Python code will run through Azure Functions.
That means I can't pass the file directory.
I need to connect to the server but I do not how.
I know the protocol, server, port, model_name, username, and password.
How can I create this string connection?
I couldn't find any useful information online, so I asked ChatGPT...
def connect_to_sparx_cloud(username, password, model_name, server_url):
# Endpoint to authenticate and obtain an access token
auth_endpoint = f"{server_url}/authenticate"
# Construct the URL to access your model
model_url = f"{server_url}/models/{model_name}"
# Make a request to authenticate and obtain an access token
response = requests.post(auth_endpoint, json={"username": username, "password": password})
# Check if authentication was successful
if response.status_code == 200:
access_token = response.json()["access_token"]
print("Authentication successful. Access token:", access_token)
# Use the access token to access your model
headers = {"Authorization": f"Bearer {access_token}"}
model_response = requests.get(model_url, headers=headers)
# Check if model access was successful
if model_response.status_code == 200:
model_data = model_response.json()
print("Model details:", model_data)
return model_data
else:
print("Failed to access model. Status code:", model_response.status_code)
return None
else:
print("Authentication failed. Status code:", response.status_code)
return None
or
def connect_to_sparx_cloud(username, password, model_name, server, port, protocol):
# Construct the base URL for the Sparx Cloud Web API
base_url = f"{protocol}{server}:{port}/services/api"
# Endpoint to authenticate and obtain an access token
auth_endpoint = f"{base_url}/authenticate"
# Construct the URL to access your model
model_url = f"{base_url}/models/{model_name}"
# Make a request to authenticate and obtain an access token
response = requests.post(auth_endpoint, json={"username": username, "password": password})
# Check if authentication was successful
if response.status_code == 200:
access_token = response.json()["access_token"]
print("Authentication successful. Access token:", access_token)
# Use the access token to access your model
headers = {"Authorization": f"Bearer {access_token}"}
model_response = requests.get(model_url, headers=headers)
# Check if model access was successful
if model_response.status_code == 200:
model_data = model_response.json()
print("Model details:", model_data)
return model_data
else:
print("Failed to access model. Status code:", model_response.status_code)
return None
else:
print("Authentication failed. Status code:", response.status_code)
return None
However, it doesn't work. I don't know what a "token" is either.