Skip to content
Snippets Groups Projects
Commit a86b1295 authored by Moul's avatar Moul
Browse files

[ref] Rework send-documents examples since urllib usage switch

parent 62c52c3d
No related branches found
No related tags found
2 merge requests!157v1.0.0rc0: merge dev into master,!134#160: Include examples into Python package
Pipeline #12550 waiting for manual action
......@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import getpass
from typing import Optional
import urllib
from duniterpy.api import bma
from duniterpy.api.client import Client
......@@ -138,12 +139,10 @@ def send_certification():
certification.sign([key])
# Here we request for the path wot/certify
response = client(bma.wot.certify, certification.signed_raw())
if response.status == 200:
print(response.read())
else:
print("Error while publishing certification: {0}".format(response.read()))
try:
client(bma.wot.certify, certification.signed_raw())
except urllib.error.HTTPError as e:
print(f"Error while publishing certification: {e}")
if __name__ == "__main__":
......
......@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import getpass
import urllib
from duniterpy.api import bma
from duniterpy.api.client import Client
......@@ -97,11 +98,10 @@ def send_identity():
identity = get_identity_document(current_block, uid, key)
# send the identity signed raw document to the node
response = client(bma.wot.add, identity.signed_raw())
if response.status == 200:
print(response.read())
else:
print("Error while publishing identity : {0}".format(response.read()))
try:
client(bma.wot.add, identity.signed_raw())
except urllib.error.HTTPError as e:
print(f"Error while publishing identity: {e}")
if __name__ == "__main__":
......
......@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import getpass
import urllib
from duniterpy.api import bma
from duniterpy.api.client import Client
......@@ -106,12 +107,10 @@ def send_membership():
membership = get_membership_document("IN", current_block, identity, key)
# send the membership signed raw document to the node
response = client(bma.blockchain.membership, membership.signed_raw())
if response.status == 200:
print(response.text())
else:
print("Error while publishing membership : {0}".format(response.text()))
try:
client(bma.blockchain.membership, membership.signed_raw())
except urllib.error.HTTPError as e:
print(f"Error while publishing membership: {e}")
if __name__ == "__main__":
......
......@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import getpass
import urllib
from duniterpy.api import bma
from duniterpy.api.client import Client
......@@ -150,12 +151,10 @@ def send_transaction():
transaction.sign([key])
# send the Transaction document to the node
response = client(bma.tx.process, transaction.signed_raw())
if response.status == 200:
print(response.read())
else:
print("Error while publishing transaction: {0}".format(response.read()))
try:
client(bma.tx.process, transaction.signed_raw())
except urllib.error.HTTPError as e:
print(f"Error while publishing transaction: {e}")
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment