wip: rest api user endpoint
This commit is contained in:
@@ -3,32 +3,54 @@
|
||||
from http import client
|
||||
import logging
|
||||
import json
|
||||
import yaml
|
||||
|
||||
host="cwsvjudo.bplaced.net"
|
||||
|
||||
with open("testApi.config.yaml", "r") as f:
|
||||
config = yaml.load(f)
|
||||
def init():
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
with open("testApi.config.yaml", "r") as f:
|
||||
from yaml import safe_load
|
||||
config = safe_load(f)
|
||||
|
||||
return config
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
connection = client.HTTPConnection(host=host, port=80, timeout=1)
|
||||
connection.request(
|
||||
method="GET",
|
||||
url="/participo/api/users",
|
||||
headers={
|
||||
"Authorization": f"Basic {config['apiKey']}"
|
||||
}
|
||||
)
|
||||
response = connection.getresponse()
|
||||
class apiCall:
|
||||
@staticmethod
|
||||
def call(
|
||||
host: str,
|
||||
url: str,
|
||||
headers: dict = None
|
||||
) -> dict:
|
||||
import requests
|
||||
|
||||
print("Status: {} and reason: {}".format(response.status, response.reason))
|
||||
r = requests.get(
|
||||
url=f"http://{host}/{url}",
|
||||
# @todo The client always awaits this timeout. Even when the meaningful body is already received.params=
|
||||
# - I don't see any of the examples out there do it different from me.
|
||||
# - The browser doesn't seem to have this problem.
|
||||
timeout=10,
|
||||
headers=headers
|
||||
)
|
||||
|
||||
body = response.read()
|
||||
try:
|
||||
print(json.dumps(json.loads(body),indent=2))
|
||||
except:
|
||||
print(f"failed to parse to json")
|
||||
print(body)
|
||||
try:
|
||||
return r.json()
|
||||
except:
|
||||
logging.error(f"failed to parse json: {r.text}")
|
||||
|
||||
connection.close()
|
||||
if __name__ == "__main__":
|
||||
config = init()
|
||||
|
||||
response = apiCall.call(
|
||||
host=config["host"],
|
||||
url="participo/api/users",
|
||||
# url = "participo/api",
|
||||
headers={
|
||||
"Authorization": f"Basic {config['apiKey']}"
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
logging.info(json.dumps(response,indent=2))
|
||||
except:
|
||||
logging.error(f"failed to parse to json:")
|
||||
logging.error(response)
|
||||
|
||||
Reference in New Issue
Block a user