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
Branches
Tags v1.3.1
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/>. ...@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import getpass import getpass
from typing import Optional from typing import Optional
import urllib
from duniterpy.api import bma from duniterpy.api import bma
from duniterpy.api.client import Client from duniterpy.api.client import Client
...@@ -138,12 +139,10 @@ def send_certification(): ...@@ -138,12 +139,10 @@ def send_certification():
certification.sign([key]) certification.sign([key])
# Here we request for the path wot/certify # Here we request for the path wot/certify
response = client(bma.wot.certify, certification.signed_raw()) try:
client(bma.wot.certify, certification.signed_raw())
if response.status == 200: except urllib.error.HTTPError as e:
print(response.read()) print(f"Error while publishing certification: {e}")
else:
print("Error while publishing certification: {0}".format(response.read()))
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
import getpass import getpass
import urllib
from duniterpy.api import bma from duniterpy.api import bma
from duniterpy.api.client import Client from duniterpy.api.client import Client
...@@ -97,11 +98,10 @@ def send_identity(): ...@@ -97,11 +98,10 @@ def send_identity():
identity = get_identity_document(current_block, uid, key) identity = get_identity_document(current_block, uid, key)
# send the identity signed raw document to the node # send the identity signed raw document to the node
response = client(bma.wot.add, identity.signed_raw()) try:
if response.status == 200: client(bma.wot.add, identity.signed_raw())
print(response.read()) except urllib.error.HTTPError as e:
else: print(f"Error while publishing identity: {e}")
print("Error while publishing identity : {0}".format(response.read()))
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
import getpass import getpass
import urllib
from duniterpy.api import bma from duniterpy.api import bma
from duniterpy.api.client import Client from duniterpy.api.client import Client
...@@ -106,12 +107,10 @@ def send_membership(): ...@@ -106,12 +107,10 @@ def send_membership():
membership = get_membership_document("IN", current_block, identity, key) membership = get_membership_document("IN", current_block, identity, key)
# send the membership signed raw document to the node # send the membership signed raw document to the node
response = client(bma.blockchain.membership, membership.signed_raw()) try:
client(bma.blockchain.membership, membership.signed_raw())
if response.status == 200: except urllib.error.HTTPError as e:
print(response.text()) print(f"Error while publishing membership: {e}")
else:
print("Error while publishing membership : {0}".format(response.text()))
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
import getpass import getpass
import urllib
from duniterpy.api import bma from duniterpy.api import bma
from duniterpy.api.client import Client from duniterpy.api.client import Client
...@@ -150,12 +151,10 @@ def send_transaction(): ...@@ -150,12 +151,10 @@ def send_transaction():
transaction.sign([key]) transaction.sign([key])
# send the Transaction document to the node # send the Transaction document to the node
response = client(bma.tx.process, transaction.signed_raw()) try:
client(bma.tx.process, transaction.signed_raw())
if response.status == 200: except urllib.error.HTTPError as e:
print(response.read()) print(f"Error while publishing transaction: {e}")
else:
print("Error while publishing transaction: {0}".format(response.read()))
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment