From 9a8495ddeb6310ce8e4931c72a923f5cf7893a7a Mon Sep 17 00:00:00 2001 From: meow Date: Mon, 28 Oct 2019 15:42:32 +0500 Subject: [PATCH] Issue Fixed --- ungleich_ripe.py | 58 ++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/ungleich_ripe.py b/ungleich_ripe.py index 2d3fce4..77aaf09 100644 --- a/ungleich_ripe.py +++ b/ungleich_ripe.py @@ -3,9 +3,10 @@ import ipaddress import json import urllib.request import pprint +import requests # RIPE_URL = "https://rest.db.ripe.net/{source}/{objecttype}/{key}" -RIPE_URL = "https://rest.db.ripe.net/ripe" +# RIPE_URL = "https://rest.db.ripe.net/ripe" RIPE_URL = "https://rest-test.db.ripe.net/test" class ungleichRIPE(object): @@ -33,47 +34,50 @@ class ungleichRIPE(object): print("Sorry, {} does not look like an IPv6 network: {}".format(args.network, e)) raise - url = "{}/route6/?password={}".format(RIPE_URL, args.password) + url = "{}/route6?password={}".format(RIPE_URL, args.password) ripe_object = {} ripe_object['route6'] = args.network ripe_object['origin'] = "AS209898" ripe_object['descr'] = args.description ripe_object['mnt-by'] = "mnt-ungleich" + ripe_object['source'] = "TEST" ripe_attributes = [{ "name": key, "value": value } for key, value in ripe_object.items() ] # Format according to API layout ripe_element = {} - ripe_element['objects'] = [] - ripe_element['objects'].append( - { "object": - [ - { - "attributes": { - "attribute": ripe_attributes - } - } - ] - } - ) + ripe_element['objects'] = { + "object": [ + { + "attributes": { + "attribute": ripe_attributes + } + } + ] + } data = json.dumps(ripe_element).encode('utf-8') # debug - pprint.pprint(ripe_element) + # pprint.pprint(ripe_element) - method = 'POST' + # method = 'POST' + # req = urllib.request.Request(url=url, + # data=data, + # method='POST', + # headers={ + # "Content-Type": "application/json", + # "Accept": "application/json" + # }) + # print("Adding a v6 route object at {} for {} with {} req={}".format(url, args.network, data, str(req))) - req = urllib.request.Request(url=url, - data=data, - method='POST', - headers={ - "Content-Type": "application/json", - "Accept": "application/json" - }) + # with urllib.request.urlopen(req) as f: + # print(f.read().decode('utf-8')) - print("Adding a v6 route object at {} for {} with {} req={}".format(url, args.network, data, str(req))) - - with urllib.request.urlopen(req) as f: - print(f.read().decode('utf-8')) + r = requests.post(url, data=data, headers={ + "Content-Type": "application/json", + "Accept": "application/json" + }) + pprint.pprint(json.loads(r.content.decode("utf-8"))) + # print(r.content.decode("utf-8")) \ No newline at end of file