LINUX.ORG.RU

swagger api client как передать -H «accept: application/json» -H «Authorization: Token aaa»

 


0

1
def user_register_list_with_http_info(self, **kwargs):
        """
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.user_register_list_with_http_info(callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = []
        all_params.append('callback')
        all_params.append('_return_http_data_only')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method user_register_list" % key
                )
            params[key] = val
        del params['kwargs']

        resource_path = '/user/register/'.replace('{format}', 'json')
        path_params = {}

        query_params = {}

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['DRF Token']

        return self.api_client.call_api(resource_path, 'GET',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type=None,
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'))

Я делаю:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

from client import swagger_client
from client.swagger_client.rest import ApiException
from client.swagger_client.apis.user_api import UserApi


TARGET = {"host": "http://127.0.0.1", "port": "9996"}

configuration = swagger_client.Configuration()
configuration.host = "%s:%s" % (TARGET["host"], TARGET["port"])

api = UserApi()
# print(dir(api.user_register_list))
print(api.user_register_list())

Мне надо передать в api.user_register_list()

 -H  «accept: application/json» -H  «Authorization: Token aaa»
★★★★