44 lines
975 B
Python
44 lines
975 B
Python
import json
|
|
import sys
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
|
|
SERVER_URL = "http://localhost:5079/save?source=python-client"
|
|
|
|
|
|
def main() -> int:
|
|
payload = {
|
|
"function_name": "keyvalue_insert",
|
|
"arguments": [
|
|
"example-namespace",
|
|
"example-key",
|
|
"hello from python",
|
|
],
|
|
}
|
|
|
|
data = json.dumps(payload).encode("utf-8")
|
|
request = urllib.request.Request(
|
|
SERVER_URL,
|
|
data=data,
|
|
headers={
|
|
"Content-Type": "application/json",
|
|
"X-Client": "PersistenceServerPythonClient",
|
|
},
|
|
method="POST",
|
|
)
|
|
|
|
try:
|
|
with urllib.request.urlopen(request) as response:
|
|
body = response.read().decode("utf-8")
|
|
print(f"status: {response.status}")
|
|
print(f"body: {body}")
|
|
return 0
|
|
except urllib.error.URLError as error:
|
|
print(f"request failed: {error}", file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|