develop version for new api concept
This commit is contained in:
33
homepage/participo/testApi.py
Normal file
33
homepage/participo/testApi.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
|
||||
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()
|
||||
|
||||
print("Status: {} and reason: {}".format(response.status, response.reason))
|
||||
|
||||
body = response.read()
|
||||
try:
|
||||
print(json.dumps(json.loads(body),indent=2))
|
||||
except:
|
||||
print(f"failed to parse to json")
|
||||
print(body
|
||||
)
|
||||
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user