URL Fixed, JSON body needs another attribute i.e source
This commit is contained in:
parent
992bd6d11b
commit
a59e33149f
3 changed files with 48 additions and 39 deletions
5
Pipfile
5
Pipfile
|
|
@ -4,6 +4,7 @@ verify_ssl = true
|
|||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
apixu = {git = "https://github.com/apixu/apixu-python.git",ref = "master"}
|
||||
requests = "*"
|
||||
pyotp = "*"
|
||||
|
||||
|
|
@ -11,7 +12,3 @@ pyotp = "*"
|
|||
|
||||
[requires]
|
||||
python_version = "3.7"
|
||||
|
||||
[packages.apixu]
|
||||
git = "https://github.com/apixu/apixu-python.git"
|
||||
ref = "master"
|
||||
|
|
|
|||
24
Pipfile.lock
generated
24
Pipfile.lock
generated
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "ca9c2522bf07f03d1588afe76e9f6fc73bc1efec20d4f155d82b709efaf14a56"
|
||||
"sha256": "01bd2ed801b62b47100921e0ace284388d352ad9433e70331c082550bf830e03"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
|
@ -18,14 +18,14 @@
|
|||
"default": {
|
||||
"apixu": {
|
||||
"git": "https://github.com/apixu/apixu-python.git",
|
||||
"ref": "master"
|
||||
"ref": "370216999346d5caf7f8dc6724b5766dcc6da25d"
|
||||
},
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5",
|
||||
"sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae"
|
||||
"sha256:e4f3620cfea4f83eedc95b24abd9cd56f3c4b146dd0177e83a21b4eb49e21e50",
|
||||
"sha256:fd7c7c74727ddcf00e9acd26bba8da604ffec95bf1c2144e67aff7a8b50e6cef"
|
||||
],
|
||||
"version": "==2019.3.9"
|
||||
"version": "==2019.9.11"
|
||||
},
|
||||
"chardet": {
|
||||
"hashes": [
|
||||
|
|
@ -41,6 +41,14 @@
|
|||
],
|
||||
"version": "==2.8"
|
||||
},
|
||||
"pyotp": {
|
||||
"hashes": [
|
||||
"sha256:c88f37fd47541a580b744b42136f387cdad481b560ef410c0d85c957eb2a2bc0",
|
||||
"sha256:fc537e8acd985c5cbf51e11b7d53c42276fee017a73aec7c07380695671ca1a1"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.3.0"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
"sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4",
|
||||
|
|
@ -51,10 +59,10 @@
|
|||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:b246607a25ac80bedac05c6f282e3cdaf3afb65420fd024ac94435cabe6e18d1",
|
||||
"sha256:dbe59173209418ae49d485b87d1681aefa36252ee85884c31346debd19463232"
|
||||
"sha256:3de946ffbed6e6746608990594d08faac602528ac7015ac28d33cee6a45b7398",
|
||||
"sha256:9a107b99a5393caf59c7aa3c1249c16e6879447533d0887f4336dde834c7be86"
|
||||
],
|
||||
"version": "==1.25.3"
|
||||
"version": "==1.25.6"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue