Advertisement
FiddleComputers

JSONAPI method caller (Minecraft)

Aug 7th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. #exec(open('script.py').read())
  2.  
  3. import urllib, urllib.parse, urllib.request
  4. from pprint import pprint
  5. import hashlib
  6. import json
  7.  
  8. host = "localhost"
  9. port = 65665
  10. usr = "admin"
  11. pwd = "changeme"
  12. salt = "salt"
  13.  
  14. print("Call method: ")
  15. method = input()
  16. methodToCall = urllib.parse.quote(method)
  17. print("Called "+method)
  18. arg = ""
  19. args = []
  20.  
  21. while not arg == "q":
  22.     print('Arg (q for quit): ')
  23.     arg = input()
  24.     if not arg == "q":
  25.         args.append(arg)
  26.  
  27. args = urllib.parse.quote(json.dumps(args))
  28. print("Final args: ")
  29. print(args)
  30.  
  31. key = hashlib.sha256()
  32. key.update(usr.encode('utf-8'))
  33. key.update(method.encode('utf-8'))
  34. key.update(pwd.encode('utf-8'))
  35. key.update(salt.encode('utf-8'))
  36.  
  37. key = key.hexdigest()
  38. print(key)
  39.  
  40. url = "http://{}:{}/api/call?method={}&args={}&key={}".format(host, port, methodToCall, args, key)
  41. print('Tried to access '+url)
  42.  
  43. f = urllib.request.urlopen(url)
  44. response = json.loads(f.read())
  45. pprint(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement