本文整理汇总了Python中RestApiClient.RestApiClient.headers[header_pair[0]]方法的典型用法代码示例。如果您正苦于以下问题:Python RestApiClient.headers[header_pair[0]]方法的具体用法?Python RestApiClient.headers[header_pair[0]]怎么用?Python RestApiClient.headers[header_pair[0]]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestApiClient.RestApiClient
的用法示例。
在下文中一共展示了RestApiClient.headers[header_pair[0]]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_request
# 需要导入模块: from RestApiClient import RestApiClient [as 别名]
# 或者: from RestApiClient.RestApiClient import headers[header_pair[0]] [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>"')