-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjrequests.py
More file actions
62 lines (57 loc) · 1.74 KB
/
Copy pathjrequests.py
File metadata and controls
62 lines (57 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import requests
import json
def get_status(address: str) -> None:
"""
Print the status from a given address
:param address: The address to querry.
"""
# Define API and URL
url = 'https://mainnet.massa.net/api/v2'
headers = {
'Content-Type': 'application/json'
}
data = {
"jsonrpc": "2.0",
"id": 1,
"method": "get_status",
"params": [[address]]
}
try:
# Send POST request
response = requests.post(url, headers=headers, data=json.dumps(data))
# Check response status
if response.status_code == requests.codes.ok::
# Parse JSON
response_json = response.json()
print(json.dumps(response_json, indent=4))
else:
print(f"Error: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
def get_addresses(address: str) -> dict:
# Define API and URL
url = 'https://mainnet.massa.net/api/v2'
headers = {
'Content-Type': 'application/json'
}
data = {
"jsonrpc": "2.0",
"id": 1,
"method": "get_addresses",
"params": [[address]]
}
try:
# Send POST request
response = requests.post(url, headers=headers, data=json.dumps(data))
# Check response status
if response.status_code == requests.codes.ok::
# Parse JSON
response_json = response.json()
print(json.dumps(response_json, indent=4))
return response_json
else:
print(f"Error: {response.status_code}")
return {}
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
return {}