0

我正在尝试使用黑暗启动来克隆功能标志

代码是这样的

from __future__ import print_function
import time
import launchdarkly_api
from launchdarkly_api.rest import ApiException
from pprint import pprint
import json

# Configure API key authorization: Token
configuration = launchdarkly_api.Configuration()
configuration.api_key['Authorization'] = 'xxxxxxxxxxx'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Authorization'] = 'Bearer'

# create an instance of the API class
api_instance = launchdarkly_api.FeatureFlagsApi(launchdarkly_api.ApiClient(configuration))
project_key = 'default' # str | The project key, used to tie the flags together under one project so they can be managed together.
feature_flag_body = launchdarkly_api.FeatureFlagBody('test', 'key', variations=['true']) # FeatureFlagBody | Create a new feature flag.
clone = 'logging-level' # str | The key of the feature flag to be cloned. The key identifies the flag in your code.  For example, setting clone=flagKey will copy the full targeting configuration for all environments (including on/off state) from the original flag to the new flag. (optional)

try:
    # Creates a new feature flag.
    api_response = api_instance.post_feature_flag(project_key, feature_flag_body,)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling FeatureFlagsApi->post_feature_flag: %s\n" % e)

运行代码时出现此错误

Exception when calling FeatureFlagsApi->post_feature_flag: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Connection': 'keep-alive', 'Content-Length': '131', 'Content-Type': 'application/json', 'Access-Control-Allow-Headers': 'Accept,Content-Type,Content-Length,Accept-Encoding,Authorization,X-Requested-With,X-LD-Private,X-LD-AccountId,X-LD-EnvId,X-LD-PrjId,X-LaunchDarkly-Event-Schema,X-LaunchDarkly-User-Agent,X-LaunchDarkly-Wrapper,LD-API-Version', 'Access-Control-Allow-Methods': 'OPTIONS, HEAD, GET, POST', 'Access-Control-Allow-Origin': '*', 'Access-Control-Max-Age': '300', 'Ld-Api-Version': '20191212', 'Strict-Transport-Security': 'max-age=31536000', 'X-Ratelimit-Reset': '1626788850000', 'X-Ratelimit-Route-Limit': '5', 'X-Ratelimit-Route-Remaining': '4', 'Accept-Ranges': 'bytes', 'Date': 'Tue, 20 Jul 2021 13:47:26 GMT', 'Via': '1.1 varnish', 'X-Served-By': 'cache-mel11230-MEL', 'X-Cache': 'MISS', 'X-Cache-Hits': '0', 'X-Timer': 'S1626788847.518821,VS0,VE236', 
'Vary': 'Accept-Encoding, Origin', 'Age': '0'})
HTTP response body: {"code":"invalid_request","message":"json: cannot 
unmarshal string into Go struct field FlagPost.variations of type flags.Variate"}


<bound method Response.json of <Response [200]>>

我确信我没有正确传递一些信息,但不知道如何正确传递。文档中也没有明确定义。

4

0 回答 0