Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
1,392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. def getProduct():
  2. session = requests.session()
  3. url = "https://prod.jdgroupmesh.cloud/stores/footpatrolgb/products/346297_footpatrolcom?channel=iphone-app&expand=variations,informationBlocks,customisations"
  4. hawkHeader = makeHawkHeader(url, "GET")
  5. headers = {
  6. 'Host': 'prod.jdgroupmesh.cloud',
  7. 'mesh-version': 'cart=4',
  8. 'MESH-Commerce-Channel': 'iphone-app',
  9. # 'X-Request-Auth': makeHawkHeader(url, "GET"),
  10. 'X-Request-Auth': hawkHeader,
  11. 'X-API-Key': '52F096E285134DF2A9E1AFAF979BB415',
  12. 'Accept-Language': 'en-gb',
  13. 'Accept-Encoding': 'gzip, deflate',
  14. 'Accept': '*/*',
  15. 'User-Agent': 'footpatrolgb/6.3.2.1446 (iphone-app; iOS 12.4.1)',
  16. 'X-Debug': '1',
  17. 'Connection': 'close',
  18. 'X-NewRelic-ID': 'VQYDUFVWDRABUFJQAwQHVFw=',
  19. }
  20.  
  21. proxies = {"http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080"}
  22. productReq = session.get(url, headers=headers, verify=False, proxies=proxies)
  23. print(productReq)
  24. print(productReq.text)
  25.  
  26.  
  27.  
  28. def signature(url,method):
  29. secret = str.encode('')
  30. h = base64.urlsafe_b64encode(os.urandom(6))
  31. content = ''.join(chr(x) for x in h)
  32. options = {
  33. "ts": int(time.time()),
  34. "nonce": content,
  35. "method": method,
  36. "resource": "/stores/footpatrolgb/products/346297_footpatrolcom?channel=iphone-app&expand=variations,informationBlocks,customisations",
  37. "host": "prod.jdgroupmesh.cloud",
  38. "port": "80",
  39. }
  40. hash_items = [
  41. "hawk.1.header",
  42. options["ts"], # Timestamp
  43. options["nonce"], # Random nonce
  44. options.get("method", "").upper(), # UPPERCASE HTTP method
  45. options.get("resource", ""),
  46. options["host"].lower(),
  47. options["port"],
  48. "",
  49. "",
  50. "",
  51. ]
  52. hash_items = map(str, hash_items)
  53. hash_str = '\n'.join(hash_items)
  54. # Generate HMAC using sha256
  55. h = base64.b64encode(hmac.new(secret, hash_str.encode('utf-8'), hashlib.sha256).digest())
  56. mac = ''.join(chr(x) for x in h)
  57. return mac, options
  58.  
  59.  
  60. def makeHawkHeader(url, method):
  61. key = ""
  62. mac, options = signature(url, method)
  63. header_items = [
  64. 'id="%s"' % key,
  65. 'ts="%s"' % options["ts"],
  66. 'nonce="%s"' % options["nonce"],
  67. ]
  68.  
  69. if options.get("ext", None):
  70. header_items.append('ext="%s"' % options["ext"])
  71. header_items.append('mac="%s"' % mac)
  72. return 'Hawk ' + ', '.join(header_items)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement