Browse Source

Pass request data dict as json arg, not data arg

`requests.post` data argument is used to send that in the **body** request,
not as json header.
The json argument can be a dictionary and doesn't need to be converted to
string.
master
juga 2 years ago
parent
commit
206e7eba0c
1 changed files with 26 additions and 17 deletions
  1. +26
    -17
      pygnunetrest/gnunetrest.py

+ 26
- 17
pygnunetrest/gnunetrest.py View File

@ -51,7 +51,7 @@ class GNUnetRest:
def create_identity(self, identity_name):
"""Creates Identy, returns True if successful, tuple if not."""
r = requests.post(self.identity, {"name": identity_name})
r = requests.post(self.identity, json={"name": identity_name})
return r.ok if r.ok else (False, r.reason)
def change_identity_name(self, identity_name, new_identity_name):
@ -62,7 +62,7 @@ class GNUnetRest:
"""
r = requests.put(
self.identity_name + identity_name,
{"newname": new_identity_name}
json={"newname": new_identity_name}
)
return True if r.ok else (False, r.reason)
@ -81,7 +81,7 @@ class GNUnetRest:
"""
r = requests.put(
self.identity_subsystem + identity_name,
{"subsystem": "namestore"})
json={"subsystem": "namestore"})
return True if r.ok else (False, r.reason)
def list_namestore_entries(self, zone):
@ -91,18 +91,20 @@ class GNUnetRest:
def add_namestore_entry(self, zone, record_name, value, record_type):
"""Adds a namestore entry, returns true if successful, tuple if not."""
data = {
'value': value,
'record_type': record_type,
# It needs to send all flags, otherwise it'd return 500.
entry = {
'record_name': record_name,
"expiration_time": "1d",
"private": False,
"relative_expiration": False,
"supplemental": False,
"shadow": False,
'data': [{
'value': value,
'record_type': record_type,
"expiration_time": "1d",
"private": False,
"relative_expiration": False,
"supplemental": False,
"shadow": False,
}]
}
r = requests.post(self.namestore + zone, data)
r = requests.post(self.namestore + zone, json=entry)
return True if r.ok else (False, r.reason)
def change_namestore_entry(self, zone, record_name, value, record_type):
@ -111,12 +113,19 @@ class GNUnetRest:
returns true if successful, tuple if not.
"""
data = {
'value': value,
'record_type': record_type,
entry = {
'record_name': record_name,
'data': [{
'value': value,
'record_type': record_type,
"expiration_time": "1d",
"private": False,
"relative_expiration": False,
"supplemental": False,
"shadow": False,
}]
}
r = requests.put(self.namestore + zone, data)
r = requests.put(self.namestore + zone, json=entry)
return True if r.ok else (False, r.reason)
def delete_namestore_entry(self, zone, record_name):


Loading…
Cancel
Save