If you call GetObject to download an object in a bucket with versioning enabled or suspended, only the current version of the object is returned by default.

When you perform the GetObject operation on an object in a bucket:
  • If the current version of the object is a delete marker, the 4040 Not Found error is returned.
  • If you specify the versionId of the target object in the request, the specified version of the object is returned. For example, if the versionId is specified as null in the request, the version of which the versionId is null is returned.
  • If the version specified in the request is a delete marker, the 405 Method Not Allowed error is returned.
You can run the following code to download 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 the RAM console.
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, 'http://oss-cn-hangzhou.aliyuncs.com', '<yourBucketName>')

# Downloads a specified version of the object.
params = dict()
params['versionId'] = '<yourObjectVersionId>'
object_stream = bucket.get_object('<yourObjectName>', params=params)

# Reads the content of the downloaded object.
read_content = object_stream.read()
print('get object content:', read_content)
# Views the version ID of the downloaded object.
print('get object versionid:', object_stream.versionid)

# The get_object interface returns a stream. You can get the CRC checksum of the object only after you perform the read() operation. Therefore, you must perform CRC verification after the read() operation.
if object_stream.client_crc != object_stream.server_crc:
   print "The CRC checksum between client and server is inconsistent!"