CodexBloom - Programming Q&A Platform

OCI Data Science SDK scenarios to Authenticate with Terraform Managed Resources

👀 Views: 84 💬 Answers: 1 📅 Created: 2025-06-10
OCI Data Science Terraform Python

I'm having a hard time understanding I'm learning this framework and I'm sure I'm missing something obvious here, but I'm trying to use the OCI Data Science SDK (version 2.40.0) to interact with a model I've deployed as part of my Oracle Cloud Infrastructure setup. I've successfully created the model and associated resources using Terraform, but when I attempt to authenticate using the SDK, I run into an scenario where it fails to recognize the credentials. I’ve already configured my environment with the required keys in the `~/.oci/config` file, which looks like this: ```ini [DEFAULT] user=ocid1.user.oc1..exampleuniqueID fingerprint=20:3b:97:54:6d:7d:12:3a:48:44:77:a3:88:45:5d:5f key_file=/path/to/oci_api_key.pem tenancy=ocid1.tenancy.oc1..exampleuniqueID region=us-ashburn-1 ``` When I try to authenticate using the following code snippet: ```python import oci config = oci.config.from_file() client = oci.data_science.DataScienceClient(config) ``` I receive the following behavior message: ``` oci.exceptions.ServiceError: (401, 'Unauthorized', 'Invalid credentials') ``` I’ve validated that the API key file path is correct and that the key has not been altered. Additionally, I tried regenerating the API key and updating the configuration file, but the scenario continues. I’ve also checked if the service is enabled in the console, and it is. Could the scenario be related to how Terraform manages the resources? I've noticed that the model and project are set up in a compartment that’s different from the one specified in my config file. I tried using the compartment's OCID in the SDK calls but that didn’t change the outcome. Any insights or recommendations on resolving this authentication scenario would be greatly appreciated! My development environment is Linux. This is my first time working with Python stable. Am I missing something obvious? This issue appeared after updating to Python 3.10. Any suggestions would be helpful.