import config
import requests
import json
import logging


class MyToken(object):
    def __init__(self):
        self._username = config.TOKEN_USERNAME
        self._password = config.TOKEN_PASSWORD
        self.token = None
        if not self.token:
            self.token = self.access_token()

    def access_token(self):
        headers = {'Content-Type': 'application/json'}
        data = {
            'username': self._username,
            'password': self._password,
        }
        try:
            response = requests.post(r"{}/api/node/token/generate/".format(config.WEBAPI_DOMAIN),
                                     headers=headers,
                                     data=json.dumps(data),
                                     timeout=1)
            rest = response.json()
            if rest['result'] == 'success':
                return rest['access_token']
        except Exception as e:
            logging.error("请求token出错:{}".format(e))
        return None


token = MyToken()
# print(token.token)
print(token.token)

42fba3e0864ed635e0f231e12a0b01a4821095c8
<mask token>


class MyToken(object):
    <mask token>

    def access_token(self):
        headers = {'Content-Type': 'application/json'}
        data = {'username': self._username, 'password': self._password}
        try:
            response = requests.post('{}/api/node/token/generate/'.format(
                config.WEBAPI_DOMAIN), headers=headers, data=json.dumps(
                data), timeout=1)
            rest = response.json()
            if rest['result'] == 'success':
                return rest['access_token']
        except Exception as e:
            logging.error('请求token出错:{}'.format(e))
        return None


<mask token>

<mask token>


class MyToken(object):

    def __init__(self):
        self._username = config.TOKEN_USERNAME
        self._password = config.TOKEN_PASSWORD
        self.token = None
        if not self.token:
            self.token = self.access_token()

    def access_token(self):
        headers = {'Content-Type': 'application/json'}
        data = {'username': self._username, 'password': self._password}
        try:
            response = requests.post('{}/api/node/token/generate/'.format(
                config.WEBAPI_DOMAIN), headers=headers, data=json.dumps(
                data), timeout=1)
            rest = response.json()
            if rest['result'] == 'success':
                return rest['access_token']
        except Exception as e:
            logging.error('请求token出错:{}'.format(e))
        return None


<mask token>

<mask token>


class MyToken(object):

    def __init__(self):
        self._username = config.TOKEN_USERNAME
        self._password = config.TOKEN_PASSWORD
        self.token = None
        if not self.token:
            self.token = self.access_token()

    def access_token(self):
        headers = {'Content-Type': 'application/json'}
        data = {'username': self._username, 'password': self._password}
        try:
            response = requests.post('{}/api/node/token/generate/'.format(
                config.WEBAPI_DOMAIN), headers=headers, data=json.dumps(
                data), timeout=1)
            rest = response.json()
            if rest['result'] == 'success':
                return rest['access_token']
        except Exception as e:
            logging.error('请求token出错:{}'.format(e))
        return None


<mask token>
print(token.token)

<mask token>


class MyToken(object):

    def __init__(self):
        self._username = config.TOKEN_USERNAME
        self._password = config.TOKEN_PASSWORD
        self.token = None
        if not self.token:
            self.token = self.access_token()

    def access_token(self):
        headers = {'Content-Type': 'application/json'}
        data = {'username': self._username, 'password': self._password}
        try:
            response = requests.post('{}/api/node/token/generate/'.format(
                config.WEBAPI_DOMAIN), headers=headers, data=json.dumps(
                data), timeout=1)
            rest = response.json()
            if rest['result'] == 'success':
                return rest['access_token']
        except Exception as e:
            logging.error('请求token出错:{}'.format(e))
        return None


token = MyToken()
print(token.token)

import config
import requests
import json
import logging


class MyToken(object):
    def __init__(self):
        self._username = config.TOKEN_USERNAME
        self._password = config.TOKEN_PASSWORD
        self.token = None
        if not self.token:
            self.token = self.access_token()

    def access_token(self):
        headers = {'Content-Type': 'application/json'}
        data = {
            'username': self._username,
            'password': self._password,
        }
        try:
            response = requests.post(r"{}/api/node/token/generate/".format(config.WEBAPI_DOMAIN),
                                     headers=headers,
                                     data=json.dumps(data),
                                     timeout=1)
            rest = response.json()
            if rest['result'] == 'success':
                return rest['access_token']
        except Exception as e:
            logging.error("请求token出错:{}".format(e))
        return None


token = MyToken()
# print(token.token)
print(token.token)
