Issue Fixed
This commit is contained in:
parent
992bd6d11b
commit
9a8495ddeb
1 changed files with 31 additions and 27 deletions
|
@ -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"))
|
Loading…
Reference in a new issue