Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. 1 import json
  2. 2 import requests
  3. 3
  4. 4 class AccessToken:
  5. 5 def __init__(self, url, username, password, client_id, client_secret):
  6. 6 self.token_url = url
  7. 7 self.client_id = client_id
  8. 8 self.client_secret = client_secret
  9. 9 self.data = [
  10. 10 ("grant_type", "password"),
  11. 11 ("username", username),
  12. 12 ("password", password),
  13. 13 ]
  14. 14
  15. 15
  16. 16 def get(self):
  17. 17 print('get')
  18. 18 r = requests.post(self.token_url, data=self.data, auth=(self.client_id, self.client_secret))
  19. 19 print(dir(r.request))
  20. 20 print('body: ', r.request.body)
  21. 21 print('headers: ',r.request.headers)
  22. 22 print('method: ', r.request.method)
  23. 23 print('url: ', r.request.url)
  24. 24
  25. 25 r = r.json()
  26. 26 return r.get('access_token')
  27.  
  28. ('body: ', 'grant_type=password&username=tester%40example.co.kr&password=test123%21')
  29. ('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=='})
  30. ('method: ', 'POST')
  31. ('url: ', 'http://my.api.server.co.kr/api/v2/o/token/')
  32.  
  33. $http.post ("http://v2dev.refreshclub.co.kr/api/v2/o/token/", {
  34. "client_id": "CR0qtAScCH7spFSDGHRSEEGdHc5trWIrsZtRyS",
  35. "client_secret": "Y7UJjVAQJqrKaWuT1KDSFGEWgeL9VBOChKZJDT1BDikFTHnlCFB7BSR01xMaEylwkgPsM4a4uWaKtoEkHO3gc9XrfsdQpUJpIDXgcencBftT3yrTdE4ULxIKMEzIi1F",
  36. "grant_type": "password",
  37. "username": "tester@example.co.kr",
  38. "password": "test123!"
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement