當前位置: 首頁>>代碼示例>>Python>>正文


Python RestApiClient.headers['Range']方法代碼示例

本文整理匯總了Python中RestApiClient.RestApiClient.headers['Range']方法的典型用法代碼示例。如果您正苦於以下問題:Python RestApiClient.headers['Range']方法的具體用法?Python RestApiClient.headers['Range']怎麽用?Python RestApiClient.headers['Range']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在RestApiClient.RestApiClient的用法示例。


在下文中一共展示了RestApiClient.headers['Range']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_request

# 需要導入模塊: from RestApiClient import RestApiClient [as 別名]
# 或者: from RestApiClient.RestApiClient import headers['Range'] [as 別名]
def make_request(args, settings):

    # Gets endpoint from --api ENDPOINT argument
    endpoint = args.api

    # Strips endpoint of first forward slash, if it has one. Allows user to 
    # supply or omit forward slash from beginning of endpoint.
    if str.startswith(endpoint, '/'):
        endpoint = endpoint[1:]

    # Settings dict is copied so it can be modified.
    util_settings = settings.copy()

    # Changes 'Accept' header to --response_format RESPONSE_FORMAT argument.
    util_settings['accept'] = args.response_format

    # Changes 'Version' header to --version VERSION argument, or clears the version.
    util_settings['version'] = args.version

    # Creates RestApiClient with user supplied settings. (So it doesn't fall 
    # to module defaults)
    api_client = RestApiClient(util_settings)

    # This code snippet adds any extra headers you wish to send with your api 
    # call. Must be in name1=value1+name2=value2 form.
    if args.add_headers:
        try:
            header_pairs = args.add_headers.split("+")
            for header_pair in header_pairs:
                header_pair = header_pair.split("=", 1)
                api_client.headers[header_pair[0]] = header_pair[1]
        except IndexError as ex:
            raise ParseError("Error: Parsing headers failed. Make sure headers are in format \"<name1>=<value1>+<name2>=<value2>\"", ex)

    if args.range:
        api_client.headers['Range'] = 'items='+args.range

    # This adds any query/body params to the list of query/body params.
    
    params = parse_params(args.params)

    # Checks content_type to see if it should send params as body param, or 
    # query param.
    content_type = None

    # Gets Content-type from --request_format REQUEST_FORMAT argument.
    if args.request_format:
        api_client.headers['Content-type'] = args.request_format
        content_type = args.request_format

    # If content_type is application/json, then it is sending a JSON object as
    # a body parameter.
    try:
        if content_type == 'application/json':
            data = params['data'].encode('utf-8')
            return api_client.call_api(endpoint, 'POST', data=data)
    # Else it sends all params as query parameters.
        else:
            for key, value in params.items():
                params[key] = urlparse.quote(value)
            return api_client.call_api(endpoint, args.method, params=params)
              
    except IndexError:
        raise ParseError('Error: Parameter parsing failed. Make sure any parameters follow the syntax <paramname>="<paramvalue>"')
開發者ID:phieber,項目名稱:api-samples,代碼行數:66,代碼來源:apiclient.py


注:本文中的RestApiClient.RestApiClient.headers['Range']方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。