import sys import netrc import httplib2 import json if __name__ == '__main__': if len(sys.argv) <= 1: print ("please provide a JSON as the first parameter") sys.exit(1) data = {} with open(sys.argv[1]) as data_file: data = json.load(data_file) extra_param = "" if len(sys.argv) == 3: if sys.argv[2] == "test": extra_param = "?test=1" if sys.argv[2] == "check": extra_param = "?check=1" if len(sys.argv) == 4 and sys.argv[2] == "check" and sys.argv[3] == "test": extra_param = "?tcheck=1" print(extra_param) info = netrc.netrc() login, account, password = info.authenticators("cera") httplib2.debuglevel = 0 http = httplib2.Http() content_type_header = "application/json" url = "http://ceracite.dkrz.de:5000/api/v1/citation"+extra_param http.add_credentials(login, password) headers = {'Content-Type': content_type_header} response, content = http.request( url, 'POST', json.dumps(data), headers=headers) print('Status: ' +str(response.status)) print(content.decode())