本文整理汇总了Python中json.get方法的典型用法代码示例。如果您正苦于以下问题:Python json.get方法的具体用法?Python json.get怎么用?Python json.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块json的用法示例。
在下文中一共展示了json.get方法的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: make_api_call_all_pages
点赞 6
# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def make_api_call_all_pages(conf, action, params = {}):
"""
A wrapper of make_api_call() to get all pages on a GET request
"""
start = 0
results = []
looping = True
params.update({'limit':conf['PAGINATION']})
while looping:
params.update({'start':start})
json = make_api_call(conf, action, params)
for r in json.get('data'):
results.append(r)
is_more = json.get('additional_data').get('pagination').get('more_items_in_collection')
if is_more:
start = json.get('additional_data').get('pagination').get('next_start')
else:
looping = False
return results
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:21,
示例2: make_api_call
点赞 6
# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def make_api_call(action, token, parameters = {}, method = 'get', data = {}):
"""
Makes an API call to Intercom
"""
headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
'Accept-Encoding': 'gzip',
'Authorization': 'Bearer %s' % token
}
if method == 'get':
r = s.request(method, 'https://api.intercom.io/'+action, headers=headers, params=parameters, timeout=30)
else:
raise ValueError('Unimplemented method.')
logging.info('Intercom plugin - API %s call: %s' % (method, r.url) )
if r.status_code < 300:
return r.json()
else:
raise Exception('API error when calling %s (code %i): %s' % (r.url, r.status_code, r.content))
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:21,
示例3: list_object
点赞 6
# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def list_object(object_name, token, parameters = {}):
"""
A generator that wraps make_api_call() to get all items of an object
"""
looping = True
parameters.update({'page': None})
while looping:
json = make_api_call(object_name, token, parameters)
logging.info('Intercom plugin - %s: results = %i' % (object_name, len(json.get(object_name))) )
for r in json.get(object_name):
yield r
next = json.get('pages', {}).get('next')
logging.info('Intercom plugin - %s: next = %s' % (object_name, next) )
if next is None:
looping = False
else:
# next contains an url, let's extract the url params
new_params = dict(urlparse.parse_qs(urlparse.urlparse(next).query))
parameters.update(new_params)
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:21,
示例4: scroll_object
点赞 6
# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def scroll_object(object_name, token, parameters = {}):
"""
A generator that wraps make_api_call() to get all items of an object using the scpecial scroll endpoint
"""
page = None
looping = True
while looping:
parameters.update({'scroll_param':page})
json = make_api_call(object_name+'/scroll', token, parameters)
logging.info('Intercom plugin - %s: scroll_param = %s' % (object_name, json.get("scroll_param")) )
logging.info('Intercom plugin - %s: results = %i' % (object_name, len(json.get(object_name))) )
for r in json.get(object_name):
yield r
page = json.get('scroll_param')
if page is None or len(json.get(object_name)) == 0:
looping = False
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:18,
示例5: get
点赞 6
# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def get(self, object_name, path=None, params=None, retries=0):
"""
Makes a GET request to the API. Checks for invalid requests that raise PardotAPIErrors. If the API key is
invalid, one re-authentication request is made, in case the key has simply expired. If no errors are raised,
returns either the JSON response, or if no JSON was returned, returns the HTTP response status code.
"""
if params is None:
params = {}
params.update({'user_key': self.user_key, 'api_key': self.api_key, 'format': 'json'})
try:
self._check_auth(object_name=object_name)
request = requests.get(self._full_path(object_name, path), params=params)
response = self._check_response(request)
return response
except PardotAPIError as err:
if err.message == 'Invalid API key or user key':
response = self._handle_expired_api_key(err, retries, 'get', object_name, path, params)
return response
else:
raise err
开发者ID:joshgeller,项目名称:PyPardot,代码行数:22,
示例6: login_page