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 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,22 +34,21 @@ 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":
[
ripe_element['objects'] = {
"object": [
{
"attributes": {
"attribute": ripe_attributes
@ -56,24 +56,28 @@ class ungleichRIPE(object):
}
]
}
)
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={
# 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"
})
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'))
pprint.pprint(json.loads(r.content.decode("utf-8")))
# print(r.content.decode("utf-8"))