02-17-2014 10:26 AM
Hi,
I find the correct method to attach a blob with the python automation client (answer how-to-call-blobattach-via-rest-api-in-python)
/>
Perfect for ascii files, but when i try to attach a blob like a pdf or a csv, I have an error UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 464: ordinal not in range(128)
I am on Ubuntu 12.04 / python 2.7.6 / Nuxeo 5.8
Someone have an idea ?
Thanks
Trace :
ERROR:root:'ascii' codec can't decode byte 0xe9 in position 464: ordinal not in range(128)
Traceback (most recent call last):
File "perso_test2.py", line 21, in <module>
s.attachBlob(doc['uid'],'/home/administrateur/test3.csv')
File "/usr/local/lib/python2.7/dist-packages/nuxeo_automation-0.1-py2.7.egg/nuxeoautomation.py", line 93, in attachBlob
return self._attach_blob(blob, document=ref)
File "/usr/local/lib/python2.7/dist-packages/nuxeo_automation-0.1-py2.7.egg/nuxeoautomation.py", line 183, in _attach_blob
resp = self.opener.open(req)
File "/usr/lib/python2.7/urllib2.py", line 400, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 418, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1207, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1174, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/usr/lib/python2.7/httplib.py", line 958, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 992, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 812, in _send_output
msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 464: ordinal not in range(128)
02-21-2014 10:06 AM
Hi,
I would suggest you use the latest version of the Python Automation client available in the python-automation-client branch of the https://github.com/nuxeo/nuxeo-automation-clients repository:
https://github.com/nuxeo/nuxeo-automation-clients/tree/python-automation-client/python
This is the result of the extraction of the Python Automation client used by Nuxeo Drive, which we put in a branch for the moment as work is still in progress. You will find:
If you want to attach a blob to an existing Nuxeo document, the following lines should do:
import automation_client
client = automation_client.BaseAutomationClient('http://server:port/nuxeo', 'usernamme', password='*****')
blob = client.execute_with_blob_streaming('Blob.Attach', '/path/to/the/file/to/upload/my_file.pdf', filename='my_file.pdf', document='/default-domain/workspaces/TestPython/TestPDFUpload')
This should solve your problem, and has the advantage of:
Hope this helps!
02-21-2014 10:06 AM
Hi,
I would suggest you use the latest version of the Python Automation client available in the python-automation-client branch of the https://github.com/nuxeo/nuxeo-automation-clients repository:
https://github.com/nuxeo/nuxeo-automation-clients/tree/python-automation-client/python
This is the result of the extraction of the Python Automation client used by Nuxeo Drive, which we put in a branch for the moment as work is still in progress. You will find:
If you want to attach a blob to an existing Nuxeo document, the following lines should do:
import automation_client
client = automation_client.BaseAutomationClient('http://server:port/nuxeo', 'usernamme', password='*****')
blob = client.execute_with_blob_streaming('Blob.Attach', '/path/to/the/file/to/upload/my_file.pdf', filename='my_file.pdf', document='/default-domain/workspaces/TestPython/TestPDFUpload')
This should solve your problem, and has the advantage of:
Hope this helps!
02-21-2014 11:57 AM
Great ! To add in the python client documentation
Thanks a lot
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.