Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 import json
- 2 import requests
- 3
- 4 class AccessToken:
- 5 def __init__(self, url, username, password, client_id, client_secret):
- 6 self.token_url = url
- 7 self.client_id = client_id
- 8 self.client_secret = client_secret
- 9 self.data = [
- 10 ("grant_type", "password"),
- 11 ("username", username),
- 12 ("password", password),
- 13 ]
- 14
- 15
- 16 def get(self):
- 17 print('get')
- 18 r = requests.post(self.token_url, data=self.data, auth=(self.client_id, self.client_secret))
- 19 print(dir(r.request))
- 20 print('body: ', r.request.body)
- 21 print('headers: ',r.request.headers)
- 22 print('method: ', r.request.method)
- 23 print('url: ', r.request.url)
- 24
- 25 r = r.json()
- 26 return r.get('access_token')
- ('body: ', 'grant_type=password&username=tester%40example.co.kr&password=test123%21')
- ('headers: ', {'Content-Length': '76', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.12.4', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic Q1IwcXRBU2NDSDdzcEZJUUplVlJZQ3lIa2RIYzV0cldJcnNadFJ5UzpZN1VKalZBUUpxckthV3VUMUtZYVpxd01DZ2VMOVZCT0NoS1pKRFQxQkRpa0ZUSG5sQ0ZCN0JTUjAxeE1hRXlsd2tnUHNNNGE0dVdhS3RvRWtITzNnYzlYcmZzZFFwVUpwSURYZ2NlbmNCZnRUM3lyVGRFNFVMeElLTUV6SWkxRg=='})
- ('method: ', 'POST')
- ('url: ', 'http://my.api.server.co.kr/api/v2/o/token/')
- $http.post ("http://v2dev.refreshclub.co.kr/api/v2/o/token/", {
- "client_id": "CR0qtAScCH7spFSDGHRSEEGdHc5trWIrsZtRyS",
- "client_secret": "Y7UJjVAQJqrKaWuT1KDSFGEWgeL9VBOChKZJDT1BDikFTHnlCFB7BSR01xMaEylwkgPsM4a4uWaKtoEkHO3gc9XrfsdQpUJpIDXgcencBftT3yrTdE4ULxIKMEzIi1F",
- "grant_type": "password",
- "username": "tester@example.co.kr",
- "password": "test123!"
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement