Hi,
I'm trying to write a simple python program to create an entry in the
new Olog server (API documented in
https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*olog.readthedocs.io/en/latest/index.html__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhJoQQa75$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg8U0SQKs$
).
I am using PUT
https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg2nzFLVA$
request and
all works fine for entries without any attachments. If I try to add an
attachment the entry itself is saved but saving the attachment fails.
I have found pyOlog library but it seems to be the old version written
for Glassfish and mysql architecture.
Does anybody have a python library, or at least an example program
showing how to use the new PUT
https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg2nzFLVA$
API for creating the entries
with an attachment. A curl command showing the use of PUT
https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*localhost:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhOZ21DPF$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg2nzFLVA$
would also be helpful.
Below is the python code that I've used:
api_endpoint =
"https://urldefense.com/v3/__https://urldefense.us/v3/__https:/*olog-server:8181/Olog/logs/multipart__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhJIczIfa$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULgp3Hr408$
"
# Prepare log entry payload
log_entry = {
"owner": "dev",
"description": "New entry using Olog/logs/multipart with one
attachment.\n",
"level": "INFO",
"title": "test4.py",
"logbooks": [{"name": "test"}],
"attachments":[
{"id": str(uuid.uuid4()), "name": "FREIAlogo-v3_March19.png"}
]
}
# Prepare the log entry payload as JSON
json_data = json.dumps(log_entry)
json_filename = json.dumps({"filename": "FREIAlogo-v3_March19.png"})
json_descr = json.dumps({"fileMetadataDescription": "image/png"})
# Prepare the multipart encoder
multipart_data = MultipartEncoder(
fields={
'logEntry': ('logEntry.json', json_data, 'application/json'),
'files': ('filename', json_filename, 'application/json'),
'files': ('fileMetadataDescription', json_descr,
'application/json'),
'files': ('FREIAlogo-v3_March19.png',
open('FREIAlogo-v3_March19.png', 'rb'), 'application/octet-stream')
}
)
# Set the Content-Type header with the boundary
headers = {
'Content-Type': multipart_data.content_type
}
try:
response = requests.put(api_endpoint, headers=headers,
data="" auth=HTTPBasicAuth(username, password))
if response.status_code == 200:
print("Log entry created successfully.")
else:
print("Failed to create log entry. Status code:
{response.status_code}")
except Exception as e:
print("An error occurred: ",{str(e)})
And a log from phoebus-olog server:
2024-04-08 13:28:42.337 DEBUG 1740 --- [nio-8181-exec-4]
o.s.web.servlet.DispatcherServlet : PUT "/Olog/logs/multipart",
parameters={multipart}
2024-04-08 13:28:42.347 DEBUG 1740 --- [nio-8181-exec-4]
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to
org.phoebus.olog.LogResource#createLog(String, String, String, Log,
MultipartFile[], Principal)
2024-04-08 13:28:42.349 DEBUG 1740 --- [nio-8181-exec-4]
.m.m.a.RequestPartMethodArgumentResolver : Read "application/json" to
[org.phoebus.olog.entity.Log@c517dec8]
2024-04-08 13:28:42.404 INFO 1740 --- [nio-8181-exec-4]
org.phoebus.olog.LogResource : Entry id 75 created from n/a
2024-04-08 13:28:42.406 WARN 1740 --- [nio-8181-exec-4]
org.phoebus.olog.LogResource : File FREIAlogo-v3_March19.png
not matched with attachment meta-data
2024-04-08 13:28:42.407 INFO 1740 --- [nio-8181-exec-4]
org.phoebus.olog.LogResource : Entry id 75 created from n/a
2024-04-08 13:28:42.408 DEBUG 1740 --- [nio-8181-exec-4]
m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json',
given [*/*] and supported [application/json, application/*+json,
application/json, application/*+json]
2024-04-08 13:28:42.408 DEBUG 1740 --- [nio-8181-exec-4]
m.m.a.RequestResponseBodyMethodProcessor : Writing
[org.phoebus.olog.entity.Log@ff3dfa85]
2024-04-08 13:28:42.410 DEBUG 1740 --- [nio-8181-exec-4]
o.s.web.servlet.DispatcherServlet : Completed 200 OK
Best regards,
Konrad
--
Konrad Gajewski
FREIA Laboratory
https://urldefense.com/v3/__https://urldefense.us/v3/__http:/*www.physics.uu.se/__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhPzk46FZ$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULg55JX090$
När du har kontakt med oss på Uppsala universitet med e-post så innebär det att vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du läsa här:
https://urldefense.com/v3/__https://urldefense.us/v3/__http:/*www.uu.se/om-uu/dataskydd-personuppgifter/__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhEJJRf56$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULgzBkyo1w$
E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here:
https://urldefense.com/v3/__https://urldefense.us/v3/__http:/*www.uu.se/en/about-uu/data-protection-policy__;!!G_uCfscf7eWS!dDgYNelpLq7ymQ7M1rIdPoepGvVQEAfQPCBtmSKeFTIOr5xieb6nu3QDLfhW7gWC1u9P52dP1-w0PfTS-T4BhX99ax7hhIzZpdTb$__;Lw!!P4SdNyxKAPE!AbLdYMLNWFaAl0vaL34bvuQ4eAbD8mlrxJZEileV55LOJ9fPWCQVaCo_9erpxOiLRET043FDvZ55tULgjKtLYtY$