Hi, I am developing my first HttpApi plugin and struggling with file upload. I am getting an error:
ansible/module_utils/connection.py", line 149, in _exec_jsonrpc
raise ConnectionError(
fatal: [device_1]: FAILED! => {
“changed”: false,
“invocation”: {
“module_args”: {
“filename”: “file.bin”,
“state”: “present”
}
},
“msg”: “Connection error occurred: Failed to encode some variables as JSON for communication with ansible-connection. The original exception was: Object of type BufferedReader is not JSON serializable”
}
The way I provide a file to my request is by file-like object - open() in “rb” mode
I’ve also tried reading the file-like object and providing it this way
None of these approaches work
I was able to get it working using requests library with:
response = session.put(url, data=open(“file.bin”, “rb”), headers={“Content-Type”: “application/octet-stream”})
Is is possible to upload a file using custom HttpApi plugin?
If so how do I provide the file to a request?
If any additional info is needed, let me know
Best Regards
Piotr Gabryś