0

Contentful Content Management APIに Python クライアントを使用していますが、 現在アセットを処理または公開できません。いずれの場合も、API は次を返します。

contentful_management.errors. NotFoundError: HTTP status code: 404 Message: The resource could not be found. Details: The requested Asset could not be found.

アセットを作成した後、その ID にアクセスできるので、その時点で処理して公開できるはずです。私のコードは以下です。私が間違っているかもしれないことを誰かが知っていますか?

"""
Creating an asset requires three steps and API calls:

1. Create an asset.
2. Process an asset.
3. Publish an asset.
"""

def create_asset(self, path):
    p = os.path.abspath(path)
    return self.authorised_user.uploads(self.test_space_id).create(p)

def process_asset(self, asset_id):
    asset = self.authorised_user.assets(self.test_space_id, self.test_environment_id).find(asset_id)
    asset.process()

def publish_asset(self, asset_id):
    asset = self.authorised_user.assets(self.test_space_id, self.test_environment_id).find(asset_id)
    asset.publish()
4

1 に答える 1

0

ファイルをアップロードしていますが、create_asset関数でアセットを作成していません。すべてのステップを実行するコードは次のとおりです。

import os
import time
from contentful_management import Client

client = Client(os.environ['CMA_TOKEN'])
space_id = 'space_id'
environment_id = 'master'
title = 'Title'
file_to_upload = '/path/to/file/image.jpeg'
fileName = os.path.basename
contentType = 'image/jpeg'

new_upload = client.uploads(space_id).create(file_to_upload)

file_attributes = {
    'fields': {
        'title': {
            'en-US': title
        },
        'file': {
            'en-US': {
                'fileName': fileName,
                'contentType': contentType,
                'uploadFrom': new_upload.to_link().to_json()
            }
        }
    }
}

new_asset = client.assets(space_id, environment_id).create(
   None, # change this to a string if you want to specify the asset ID
   file_attributes
 )

new_asset.process()

# it might take a few seconds for the asset processing to complete
while new_asset.url is None:
    time.sleep(1)
    new_asset.reload()

new_asset.publish()
于 2020-06-16T14:26:07.767 に答える