本文整理匯總了Python中restful_lib.Connection.request_get方法的典型用法代碼示例。如果您正苦於以下問題:Python Connection.request_get方法的具體用法?Python Connection.request_get怎麽用?Python Connection.request_get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類restful_lib.Connection
的用法示例。
在下文中一共展示了Connection.request_get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getBusesPositions
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def getBusesPositions(self):
lcord = []
conn = Connection("http://mc933.lab.ic.unicamp.br:8017/onibus")
response = conn.request_get("")
buses = json.loads(response["body"])
for i in buses:
response = conn.request_get(str(i))
lcord.append(json.loads(response["body"]))
#conn.request_put("/sidewinder", {'color': 'blue'}, headers={'content-type':'application/json', 'accept':'application/json'})
return lcord
示例2: _get_flavor
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def _get_flavor(attributes, vm_id):
conn = Connection(attributes["cm_nova_url"], username="", password="")
tenant_id, x_auth_token = _get_keystone_tokens(attributes)
resp = conn.request_get("/" + tenant_id +"/servers/" + vm_id, args={}, headers={'content-type':'application/json', 'accept':'application/json', 'x-auth-token':x_auth_token})
status = resp[u'headers']['status']
if status == '200' or status == '304':
server = json.loads(resp['body'])
flavor_id = server['server']['flavor']['id']
else:
log.error("Bad HTTP return code: %s" % status)
resp = conn.request_get("/" + tenant_id +"/flavors/" + flavor_id, args={}, headers={'content-type':'application/json', 'accept':'application/json', 'x-auth-token':x_auth_token})
status = resp[u'headers']['status']
if status == '200' or status == '304':
flavor = json.loads(resp['body'])
else:
log.error("_get_flavor: Bad HTTP return code: %s" % status)
return flavor['flavor']
示例3: get_style_from_geoserver
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def get_style_from_geoserver(request):
if request.method == 'GET':
layerName = request.GET.get('layer_name')
baseUrl = openthingis.settings.GEOSERVER_REST_SERVICE
conn = Connection(
baseUrl,
username=openthingis.settings.GEOSERVER_USER,
password=openthingis.settings.GEOSERVER_PASS
)
layerInfo = conn.request_get("/layers/" + layerName + '.json')
dict = layerInfo['body']
layer = simplejson.loads(dict)
deafultStyle = layer['layer']['defaultStyle']['name']
sld = conn.request_get("/styles/" + deafultStyle + '.sld')
sld_body = sld['body']
return HttpResponse(sld_body, content_type="application/xml")
示例4: _get_images
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def _get_images(attributes):
conn = Connection(attributes["cm_nova_url"], username="", password="")
tenant_id, x_auth_token = _get_keystone_tokens(attributes)
resp = conn.request_get("/" + tenant_id + "/images", args={}, headers={'content-type':'application/json', 'accept':'application/json', 'x-auth-token':x_auth_token})
status = resp[u'headers']['status']
if status == '200' or status == '304':
images = json.loads(resp['body'])
return images['images']
else:
log.error("_get_images: Bad HTTP return code: %s" % status)
示例5: DiffsClient
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
class DiffsClient(object):
_logger = logging.getLogger('DiffsClient')
_logger.addHandler(logging.StreamHandler(sys.stderr))
def __init__(self, agent_url, verbose=False):
self._logger.setLevel(logging.DEBUG if verbose else logging.NOTSET)
if not agent_url.endswith('/'):
agent_url += '/'
self.agent_url = agent_url
base_url = urljoin(agent_url, 'rest')
self._conn = Connection(base_url)
self._conn = Connection(self.get_session_url())
def get_session_url(self):
url = '/diffs/sessions'
response = self._post(url)
return response['headers']['location']
def get_diffs(self, pair_key, range_start, range_end):
url = '/?pairKey={0}&range-start={1}&range-end={2}'.format(
pair_key,
range_start.strftime(DATETIME_FORMAT),
range_end.strftime(DATETIME_FORMAT))
response = self._get(url)
return json.loads(response['body'])
def get_diffs_zoomed(self, range_start, range_end, bucketing):
"A dictionary of pair keys mapped to lists of bucketed diffs"
url = '/zoom?range-start={0}&range-end={1}&bucketing={2}'.format(
range_start.strftime(DATETIME_FORMAT),
range_end.strftime(DATETIME_FORMAT),
bucketing)
response = self._get(url)
return json.loads(response['body'])
def _get(self, url):
self._logger.debug("GET %s", self._rebuild_url(url))
response = self._conn.request_get(url)
self._logger.debug(response)
return response
def _post(self, url):
self._logger.debug("POST %s", self._rebuild_url(url))
response = self._conn.request_post(url)
self._logger.debug(response)
return response
def _rebuild_url(self, url):
return self._conn.url.geturl() + url
def __repr__(self):
return "DiffsClient(%s)" % repr(self.agent_url)
示例6: test_rest
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def test_rest(myLat, myLng):
# http://api.spotcrime.com/crimes.json?lat=40.740234&lon=-73.99103400000001&radius=0.01&callback=jsonp1339858218680&key=MLC
spotcrime_base_url = "http://api.spotcrime.com"
conn = Connection(spotcrime_base_url)
resp = conn.request_get("/crimes.json", args={ 'lat' : myLat,
'lon' : myLng,
'radius': '0.01',
'key' : 'MLC'},
headers={'Accept': 'text/json'})
resp_body = resp["body"]
return resp_body
示例7: _get_VMs
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def _get_VMs(attributes):
conn = Connection(attributes["cm_nova_url"], username="", password="")
tenant_id, x_auth_token = _get_keystone_tokens(attributes)
resp = conn.request_get("/" + tenant_id +"/servers", args={}, headers={'content-type':'application/json', 'accept':'application/json', 'x-auth-token':x_auth_token})
status = resp[u'headers']['status']
if status == '200' or status == '304':
servers = json.loads(resp['body'])
i = 0
vms = []
for r in servers['servers']:
vms.append(r['name'])
i = i+1
return vms
else:
log.error("_get_VMs: Bad HTTP return code: %s" % status)
示例8: Tinyurl
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
class Tinyurl(object):
def __init__(self):
self._conn = Connection(TINYURL_ENDPOINT)
# TODO test availability
self.active = True
def get(self, url):
# Handcraft the ?url=XXX line as Tinyurl doesn't understand urlencoded
# params - at least, when I try it anyway...
response = self._conn.request_get("?%s=%s" % (TINYURL_PARAM, url))
http_status = response['headers'].get('status')
if http_status == "200":
return response.get('body').encode('UTF-8')
else:
raise ConnectionError
示例9: _get_VM
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def _get_VM(attributes):
conn = Connection(attributes["cm_nova_url"], username="", password="")
tenant_id, x_auth_token = _get_keystone_tokens(attributes)
resp = conn.request_get("/" + tenant_id +"/servers/detail", args={}, headers={'content-type':'application/json', 'accept':'application/json', 'x-auth-token':x_auth_token})
status = resp[u'headers']['status']
found = 0
if status == '200' or status == '304':
servers = json.loads(resp['body'])
for vm in servers['servers']:
if attributes['name'] == vm['name']:
found = 1
return vm
if found == 0:
#return False
raise ResourceException("vm %s not found" % attributes['name'])
else:
log.error("_get_VM: Bad HTTP return code: %s" % status)
示例10: __init__
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
class Server:
def __init__(self, root_url="http://led-o-matic.appspot.com"):
self.root_url = root_url
self.conn = Connection(self.root_url)
self.name = ""
def getPinStatus(self, pins_name, pin_id):
request = self.name + '/' + pins_name + '/' + pin_id
response = self.conn.request_get(request)
return response['body']
def login(self, name):
self.name = name
response = self.conn.request_post('/' + name)
return self.root_url + '/' + self.name + response['body']
示例11: MeaningRecognitionAPI
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
class MeaningRecognitionAPI(object):
def __init__(self, url, app_id = None, app_key = None):
self.url = url
self.app_id = app_id
self.app_key = app_key
self.connection = Connection(self.url)
def recognize(self, text_to_recognize):
args = { 'body': text_to_recognize.encode('utf-8') }
if (self.app_id):
args['app_id'] = self.app_id
if (self.app_key):
args['app_key'] = self.app_key
result = self.connection.request_get('/v1/disambiguate', args= args, headers={'Accept':'text/json'})
if (result['headers']['status'] != '200'):
raise IOError('Failed to make disambiguation request', result)
return DisambiguationResult(result["body"])
示例12: get_tariff
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def get_tariff(tariff_id, phone):
# Should also work with https protocols
rest_user = "test.lincom3000.com.ua"
rest_pass = "lSbv5sbhPfhsU9sNK4kC5"
rest_url = "http://test.lincom3000.com.ua/api"
conn = Connection(rest_url, username=rest_user, password=rest_pass)
#nibble_rate
t = "/tariff/%i/%s/" % (int(tariff_id), phone)
response = conn.request_get(t, headers={'Accept':'text/json'})
headers = response.get('headers')
status = headers.get('status', headers.get('Status'))
if status in ["200", 200]:
body = simplejson.loads(response.get('body').encode('UTF-8'))
return body.get('rate')
else:
return None
示例13: JajahTTSClient
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
class JajahTTSClient(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
self.ip="184.73.181.226"
self.port="8090"
self.protocol="http"
self.path="/text.php"
def set_connection(self):
self.base_url= self.protocol + "://" + self.ip +":"+ str(self.port) + self.path
self.conn = Connection(self.base_url)
def send_text_message_to_jajah_tts(self,message):
response = self.conn.request_get("?text="+message)
return response['headers']['status'], response['body']
示例14: getIncidents
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def getIncidents(numberOfIncidents, sortedby):
base_url = PAGER_DUTY
conn = Connection(base_url)
yesterdayDateTime, todayDateTime = getLast24Hours()
fields = 'status,created_on,assigned_to_user'
# Specify authorization token
# Specify content type - json
resp = conn.request_get("/api/v1/incidents", args={'limit': numberOfIncidents, 'since': yesterdayDateTime, 'until': todayDateTime, 'sort_by' : sortedby, 'fields' : fields}, headers={'Authorization': 'Token token=' + AUTHORIZATION_CODE, 'content-type':'application/json', 'accept':'application/json'})
status = resp[u'headers']['status']
body = json.loads(resp[u'body'])
# check that we got a successful response (200)
if status == '200':
print json.dumps(body, sort_keys=False, indent=4, separators=(',', ': '))
else:
print 'Error status code: ', status
print "Response", json.dumps(body, sort_keys=False, indent=4, separators=(',', ': '))
示例15: main
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import request_get [as 別名]
def main():
logging.basicConfig(level=logging.DEBUG)
try:
os.remove('out.sqlite3')
except OSError as e:
if e.errno != 2:
raise
db = create_database('out.sqlite3')
logging.info('requesting new topic tree...')
base_url = 'http://www.khanacademy.org/api/v1/'
conn = Connection(base_url)
response = conn.request_get('/topictree')
logging.info('parsing json response...')
tree = json.loads(response.get('body'))
logging.info('writing to file...')
with open('../topictree', 'w') as f:
f.write(json.dumps(tree))
logging.info('loading topic tree file...')
with open('../topictree', 'r') as f:
tree = json.loads(f.read())
# stick videos in one list and topics in another for future batch insert
topics = []
videos = []
topicvideos = []
logging.info('parsing tree...')
parse_topic(tree, '', topics, videos, topicvideos)
logging.info('inserting topics...')
insert_topics(db, topics)
logging.info('inserting videos...')
insert_videos(db, videos)
logging.info('inserting topicvideos...')
insert_topicvideos(db, topicvideos)
db.commit()
logging.info('done!')