设置全局变量的瓶子

时间:2020-05-25 09:41:38

标签: python global-variables bottle

我试图将一些变量保存为全局变量,但是在另一个函数中,我得到的是空字典。

第59行-192.168.204.169 {'uid':['{14EEFF8F-E469-C174-8906-AE36EBF5CD94}'],'device':'35'}

第87行-所选规则为{}

_local_bottle = bottle.Bottle()
devices = {}
selected = {}


def get_bottle():
    return _local_bottle

@_local_bottle.route(base_url_path, method='POST')
def sending_exception_api_call():
    global selected
    postdata = bottle.request.body.read()
    host = bottle.request.environ.get('HTTP_X_FORWARDED_HOST')
    logger.info("Sending the API exception request")
    selected = json.loads(postdata)
    logger.info("{}\n{}".format(host, selected))
    devices_dict = {device.id: device.name for device in devices}
    logger.info("devices: {}".format(devices_dict))

@_local_bottle.route(base_url_path+'/exception_form', method="POST")
def get_info_for_exception_request():
    global selected
    logger.info("Sending the exception API request")
    logger.info(bottle.request.body.read())
    postdata = str(bottle.request.body.read()).split('&')
    requester = postdata[0].split('=')
    approver = postdata[1].split('=')
    expiration_date = postdata[2].split('=')
    logger.info("Got the following fields. requester: {}, approver: {}, expiration_date: {}".format(requester[1],                                                                                               approver[1],
                                                                                                    expiration_date[1]))
    logger.info("Selected rules are {}".format(selected))
    rules = get_rules(selected['device'])
    logger.info('Rules are {}'.format(rules))

0 个答案:

没有答案