本文整理汇总了Python中twisted.web.client.Agent.addCallbacks方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.addCallbacks方法的具体用法?Python Agent.addCallbacks怎么用?Python Agent.addCallbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.client.Agent
的用法示例。
在下文中一共展示了Agent.addCallbacks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _exists_d
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import addCallbacks [as 别名]
def _exists_d(url):
def handle_response(response):
return response.code in (200, 301, 302)
def handle_error(reason):
reason.printTraceback()
dfrd = Agent(reactor).request('POST', url)
dfrd.addCallbacks(handle_response, handle_error)
return dfrd
示例2: event
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import addCallbacks [as 别名]
def event(self, title, text, date_happened=None, handle=None, priority=None, related_event_id=None, tags=None, host=config.dataDog.eventHostName, device_name=None, aggregation_key="FreeSwitch", source_type_name="FreeSwitch", **kwargs):
if config.dataDog.apiKey:
body = {
'title': "%s: %s" % (config.dataDog.eventHostName, title),
'text': text,
}
if date_happened is not None:
body['date_happened'] = date_happened
if handle is not None:
body['handle'] = handle
if priority is not None:
body['priority'] = priority
if related_event_id is not None:
body['related_event_id'] = related_event_id
if tags is not None:
body['tags'] = ','.join(tags)
if host is not None:
body['host'] = host
if device_name is not None:
body['device_name'] = device_name
if aggregation_key is not None:
body['aggregation_key'] = aggregation_key
if source_type_name is not None:
body['source_type_name'] = source_type_name
body.update(kwargs)
d = Agent(reactor).request('POST', 'https://app.datadoghq.com/api/v1/events?api_key='+config.dataDog.apiKey, Headers({'Content-Type': ['application/json']}), JSONProducer(body))
d.addCallbacks(self.eventHandleResponse, self.eventHandleError)