tornado框架

import os
import json
from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPClient

# token
def get_token():
    http_client = HTTPClient()
    req = HTTPRequest("%s/authorizations/user_token/%s" % (os.environ.get('JPY_HUB_API_URL'), os.environ.get('JPY_USER')),
            method="GET",
            headers={
                "Authorization": "token %s" % os.environ.get('JPY_HUB_API_TOKEN'),
                "Host":"192.168.176.100",
                "Referer":"%s/authorizations/user_token" % os.environ.get('JPY_HUB_API_URL'),
            }
        )
    resp = http_client.fetch(req)
    resp_json = json.loads(resp.body.decode('utf8', 'replace'))
    
    return resp_json["user_token"]

def get_market_list():
    url = 'https://xxxx.xx.xxx/quote/v1/market/list'
    
    http_client = HTTPClient()
    req = HTTPRequest(url,
        method="GET",
        headers={
            "Authorization": "Bearer %s" % get_token(),
        }
    )
    resp = http_client.fetch(req)
    
    return json.loads(resp.body.decode('utf8', 'replace'))
原文地址:https://www.cnblogs.com/jzm17173/p/5120972.html