-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.py
37 lines (26 loc) · 1.09 KB
/
connection.py
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
import requests
# import aiohttp
import json
from exceptions import QueryError
ARCHETHIC_MAINNET = "https://mainnet.archethic.net"
ARCHETHIC_TESTNET = "https://testnet.archethic.net"
class Connection:
def __init__(self, endpoint = ARCHETHIC_MAINNET):
self.endpoint = endpoint
def executeQuery(self, query):
req = requests.post(self.endpoint + "/api", headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}, data = json.dumps({"query": query}))
req.raise_for_status()
req_json = req.json()
if "errors" in req_json:
raise QueryError(req_json["errors"], query)
return req_json
# async def asyncExecuteQuery(self, query, session: aiohttp.ClientSession):
# async with session.post(self.endpoint + "/api", data = json.dumps({"query": query})) as req:
# req_json = await req.json()
# if "errors" in req_json:
# raise QueryError(req_json["errors"], query)
# return req_json
con = Connection()