Issue Fixed

This commit is contained in:
ahmadbilalkhalid 2019-10-28 15:42:32 +05:00
parent 992bd6d11b
commit 9a8495ddeb

View file

@ -3,9 +3,10 @@ import ipaddress
import json import json
import urllib.request import urllib.request
import pprint import pprint
import requests
# RIPE_URL = "https://rest.db.ripe.net/{source}/{objecttype}/{key}" # 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" RIPE_URL = "https://rest-test.db.ripe.net/test"
class ungleichRIPE(object): class ungleichRIPE(object):
@ -33,22 +34,21 @@ class ungleichRIPE(object):
print("Sorry, {} does not look like an IPv6 network: {}".format(args.network, e)) print("Sorry, {} does not look like an IPv6 network: {}".format(args.network, e))
raise raise
url = "{}/route6/?password={}".format(RIPE_URL, args.password) url = "{}/route6?password={}".format(RIPE_URL, args.password)
ripe_object = {} ripe_object = {}
ripe_object['route6'] = args.network ripe_object['route6'] = args.network
ripe_object['origin'] = "AS209898" ripe_object['origin'] = "AS209898"
ripe_object['descr'] = args.description ripe_object['descr'] = args.description
ripe_object['mnt-by'] = "mnt-ungleich" ripe_object['mnt-by'] = "mnt-ungleich"
ripe_object['source'] = "TEST"
ripe_attributes = [{ "name": key, "value": value } for key, value in ripe_object.items() ] ripe_attributes = [{ "name": key, "value": value } for key, value in ripe_object.items() ]
# Format according to API layout # Format according to API layout
ripe_element = {} ripe_element = {}
ripe_element['objects'] = [] ripe_element['objects'] = {
ripe_element['objects'].append( "object": [
{ "object":
[
{ {
"attributes": { "attributes": {
"attribute": ripe_attributes "attribute": ripe_attributes
@ -56,24 +56,28 @@ class ungleichRIPE(object):
} }
] ]
} }
)
data = json.dumps(ripe_element).encode('utf-8') data = json.dumps(ripe_element).encode('utf-8')
# debug # 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, # with urllib.request.urlopen(req) as f:
data=data, # print(f.read().decode('utf-8'))
method='POST',
headers={ r = requests.post(url, data=data, headers={
"Content-Type": "application/json", "Content-Type": "application/json",
"Accept": "application/json" "Accept": "application/json"
}) })
pprint.pprint(json.loads(r.content.decode("utf-8")))
print("Adding a v6 route object at {} for {} with {} req={}".format(url, args.network, data, str(req))) # print(r.content.decode("utf-8"))
with urllib.request.urlopen(req) as f:
print(f.read().decode('utf-8'))