(Optional) Session Authentication
Overview
The session module authenticates resources and initializes ModelArts SDK Client and OBS Client. After a session is set up, you can directly call the ModelArts SDKs.
- ModelArts notebook does not require session authentication. The sample code is as follows:
1 2
from modelarts.session import Session session = Session()
- Session authentication is required when the local PC uses ModelArts SDKs. You can select either of the following authentication modes:
- Authentication Using the Username and Password: Available for OBS Management, Data Management, Training Management, Model Management, and Service Management.
- AK/SK-based Authentication: Available for OBS Management, Data Management, Training Management, Model Management, and Service Management.
Authentication Using the Username and Password
After installing the ModelArts SDK on the local PC, you can perform session authentication using the username and password. The sample code is as follows:
- Authentication using an account
Set username to your account name.
1 2 3 4 5 6 7
from modelarts.session import Session # Hardcoded or plaintext password is risky. For security, encrypt your password and store it in the configuration file or environment variables. # In this example, the password is stored in environment variables for identity authentication. Before running this example, set environment variable HUAWEICLOUD_SDK_PASSWORD. __PASSWORD = os.environ["HUAWEICLOUD_SDK_PASSWORD"] # Decrypt the password if it is encrypted. session = Session(username='***', password=__PASSWORD, region_name='***', project_id='***')
AK/SK-based Authentication
After installing the ModelArts SDK on the local PC, you can perform session authentication using the AK/SK. The sample code is as follows:
1 2 3 4 5 6 7 8 |
from modelarts.session import Session # Hardcoded or plaintext AK/SK is risky. For security, encrypt your AK/SK and store them in the configuration file or environment variables. # In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK. __AK = os.environ["HUAWEICLOUD_SDK_AK"] __SK = os.environ["HUAWEICLOUD_SDK_SK"] # Decrypt the password if it is encrypted. session = Session(access_key=__AK,secret_key=__SK, project_id='***', region_name='***') |
Parameters are as follows:
- For details about how to obtain the values of access_key and secret_key, see "Obtaining an Access Key" in User Guide.
- project_id indicates the project ID. To obtain the project ID, do as follows:
- Log in to the management console.
- In the upper right corner, click your account avatar icon and choose My Settings from the drop-down list.
- On the My Settings page, go to the Project List tab page, which is displayed by default. View the project ID and name in the project list.
- region_name indicates the region ID. Contact the administrator to obtain a region ID.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.