Created
September 20, 2019 07:48
-
-
Save kenichimiki/04f49b905efe375e0abcfbb4950e5b10 to your computer and use it in GitHub Desktop.
Sample of how to call the Mezamashi Park jankenApi from Python3 script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import urllib.request | |
import json | |
url = 'https://janken.miki-ie.com/jankenApi.php' | |
headers = { | |
'Authorization': 'Bearer @@API_KEY@@', | |
'Content-Type': 'application/json; charset=utf-8' | |
} | |
method = 'POST' | |
data = { | |
"mod": "test", | |
"date": "2019-10-01", | |
"times": 1, | |
"predict": 1 | |
} | |
json_data = json.dumps(data).encode("utf-8") | |
req = urllib.request.Request(url=url, data=json_data, headers=headers, method=method) | |
res = urllib.request.urlopen(req, timeout=30) | |
print("Http status: {0} {1}".format(res.status, res.reason)) | |
print(res.read().decode("utf-8")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment