In a bucket with versioning enabled or suspended, the storage class of each version of an object can be different. RestoreObject restores the current version of the target object by default. You can specify the versionId in the request to restore the specified version of the object.

You can run the following code to restore an object:
# -*- coding: utf-8 -*-
import oss2

# It is highly risky to log on with the AccessKey of an Alibaba Cloud account because the account has permissions on all the APIs in OSS. We recommend that you log on as a RAM user to access APIs or perform routine operations and maintenance. To create a RAM user account, log on to
auth = oss2.Auth('<yourAccessKeyId>', '<yourAccessKeySecret>')
# This example uses the China East 1 (Hangzhou) endpoint. Specify the actual endpoint based on your requirements.
bucket = oss2.Bucket(auth, '', '<yourBucketName>')

# Inputs the versionId field to the param parameter.
params = dict()
params['versionId'] = '<yourObjectVersionId>'

# Inputs the name of an object of the Archive storage class. If no object of the Archive storage class exists in the bucket, call the put_object interface to create one.
object_name = 'yourArchiveObjectName'

# Obtains the metadata of a specified version of the object.
meta = bucket.head_object(object_name, params=params)
# Determines whether the storage class of the object is Archive.
if meta.resp.headers['x-oss-storage-class'] == oss2.BUCKET_STORAGE_CLASS_ARCHIVE:
     # Restores the specified version of the object.
     result = bucket.restore_object(object_name, params=params)
     # Views the version ID of the object that is restored.
     print('restore object version id:', result.versionid)

     while True:
         meta = bucket.head_object(object_name, params=params)
         print('x-oss-restore:', meta.resp.headers['x-oss-restore'])
         # Determines the status of the restored object.
         if meta.resp.headers['x-oss-restore'] == 'ongoing-request="true"':