本文整理汇总了Python中twisted.web.client.Agent.georequest方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.georequest方法的具体用法?Python Agent.georequest怎么用?Python Agent.georequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.client.Agent
的用法示例。
在下文中一共展示了Agent.georequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_xml_from_monitor_server
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import georequest [as 别名]
def get_xml_from_monitor_server(request, url="http://62.213.6.99/cgi-bin/geocoder"):
from twisted.internet import reactor
agent = Agent(reactor)
d = agent.georequest(*request_inst_to_agent_request_list(request, url))
def callback_request(response):
print "Response version:", response.version
print "Response code:", response.code
print "Response phrase:", response.phrase
def cbRequestFinished(response_data, response, request):
for header, value in response.headers.getAllRawHeaders():
request.setHeader(header, value[0])
request.write(response_data)
request.finish()
def ebRequestFailed(reason, response, request):
print "georequest failed - {}".format(reason.getErrorMessage())
request.setResponseCode("500")
request.write("Data Retrival Failed")
finished = Deferred()
finished.addCallback(cbRequestFinished, response, request)
finished.addErrback(ebRequestFailed, response, request)
response.deliverBody(MonServBodyReceiver(finished))
return finished
d.addCallback(callback_request)
def errback(err):
print "Err"
raise err
d.addErrback(errback)
return d