2017/09/11更新 Python request get 更简单抓取
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# author=He
import json
import subprocess
class Queues:
def __new__(cls):
command = 'curl -u %s:%s http://localhost:15672/api/queues' % ('test', '123456')
result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
r = []
lists = {}
try:
r = json.loads(result.stdout.readlines()[3].decode('utf-8'))
except IndexError as e:
log_base.Error(e, mark='queues')
try:
for line in r:
if line['name']:
lists[line['name']] = line['name']
except KeyError as e:
return e
return lists