register.py
これも、メイン→サブモジュール呼び出しに対応した以外、前回と変わっていません。
import urllib.request
import json
import pprint
import settings
import sys
def register():
obj = { 'Symbols':
[
{'Symbol': settings.symbol, 'Exchange': 1}
] }
json_data = json.dumps(obj).encode('utf8')
url = 'http://localhost:' + settings.port + '/kabusapi/register'
req = urllib.request.Request(url, json_data, method='PUT')
req.add_header('Content-Type', 'application/json')
req.add_header('X-API-KEY', settings.token)
try:
print('###register')
with urllib.request.urlopen(req) as res:
print(res.status, res.reason)
for header in res.getheaders():
print(header)
print()
content = json.loads(res.read())
pprint.pprint(content)
return
except urllib.error.HTTPError as e:
print(e)
content = json.loads(e.read())
pprint.pprint(content)
except Exception as e:
print(e)
sys.exit()
if __name__ == "__main__":
import sys
register()
コメント