python get token

Requirements: Known url, authorized username, password, get token

This 示例: token currency and / data / data / access_token

 json.loads () for the type of data into str dict

Import Requests
 Import JSON
  # token acquired out separately in different places to facilitate later multiple calls 
class the Token:               
       URL = ' http://xxxxxxxxx.com/ ' 
       username = ' Shiguang ' 
       password = ' 123456 ' 
       RES = requests.get (URL, the auth = (uername, password) )
        # Print (res.text) 
       res.text_json = json.loads (res.text)    # response to the result converted res.text dictionary format, to facilitate access token in response to the results from a number of 
       # Print (res.text_json)
       = res.text_json datas_token [ ' Data ' ]   # Get the json in key = data value 
       # Print (datas_token) 
       atoken datas_token = [ ' Data ' ] [ ' the access_token ' ] # a response to a result of stripping, until you find, particularly It should be determined according to the actual response information 
       Print (atoken)
 IF  ' the __name__ ' == ' __main__ ' : 
    token = the token ()
      

 

 

Guess you like

Origin www.cnblogs.com/kite123/p/11828532.html