File UnicodeDecodeError

i have an api which needed image from erpnext Item image
i used file_manager.get_file() to get content and pass value to the api
i write test python to test the api and it works
but i write in erpnext, it shows the bug
UnicodeDecodeError: 'ascii' codec can't decode byte 0x89 in position 0: ordinal not in range(128)

how to fix it, thanks.

can you share your code?

typecasting string to unicode will help e.g. unicode('your_string')

this is my code
seachFile = frappe.db.get_value('File', {"attached_to_name":self.item_name}, ["file_name"]) content = get_file(seachFile) root = itemAPI.upload(content[0],content[1])

upload function is
def upload(self, file_name, content): self.prestashopDict.add('/images/products/32', files=[('image', file_name, content)])

and error code is
Traceback (most recent call last): File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 56, in application response = frappe.handler.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle execute_cmd(cmd) File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 42, in execute_cmd ret = frappe.call(method, **frappe.form_dict) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 907, in call return fn(*args, **newargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 22, in savedocs doc.save() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 231, in save return self._save(*args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 281, in _save self.run_post_save_methods() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 790, in run_post_save_methods self.run_method("on_update") File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 667, in run_method out = Document.hook(fn)(self, *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 892, in composer return composed(self, method, *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 875, in runner add_to_return_value(self, fn(self, *args, **kwargs)) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 661, in fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/item/item.py", line 124, in on_update root = itemAPI.upload(content[0],content[1]) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/prestashopAPI/prestapyt/prestashopItemAPI.py", line 53, in upload self.prestashopDict.add('/images/products/32', files=[('image', file_name, content)]) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/prestashopAPI/prestapyt/prestapyt.py", line 266, in add return self.add_with_url(self._api_url + resource, content, files) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/prestashopAPI/prestapyt/prestapyt.py", line 505, in add_with_url return super(PrestaShopWebServiceDict, self).add_with_url(url, xml_content, files) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/prestashopAPI/prestapyt/prestapyt.py", line 278, in add_with_url headers, body = self.encode_multipart_formdata(files) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/prestashopAPI/prestapyt/prestapyt.py", line 420, in encode_multipart_formdata body = CRLF.join(L) UnicodeDecodeError: 'ascii' codec can't decode byte 0x89 in position 0: ordinal not in range(128)