# C API: API return error code explaination

**URL:** <https://forums.sketchup.com/t/c-api-api-return-error-code-explaination/162214>\
**Category:** SketchUp SDK\
**Tags:** sketchup\
**Created:** [April 27, 2021, 8:15am UTC](https://forums.sketchup.com/t/c-api-api-return-error-code-explaination/162214 "2021-04-27T08:15:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![approtocal](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@approtocal](https://forums.sketchup.com/u/approtocal)\
**Post date:** [April 27, 2021, 8:15am UTC](https://forums.sketchup.com/t/c-api-api-return-error-code-explaination/162214/1 "2021-04-27T08:15:16Z")

</div>

Hi Expert,  
When use the Sketchup API, **SUModelCreateFromFileWithStatus** can return an error code named “SU\_ERROR\_SERIALIZATION”, can anyone let me know in what scenarios the API will return such error code? we want to know the scenario to better understand what happens when calling this API.

Thanks.  
Danny

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [April 27, 2021, 8:49am UTC](https://forums.sketchup.com/t/c-api-api-return-error-code-explaination/162214/2 "2021-04-27T08:49:20Z")

</div>

A moved your topic to right category… 😇

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 27, 2021, 5:47pm UTC](https://forums.sketchup.com/t/c-api-api-return-error-code-explaination/162214/3 "2021-04-27T17:47:12Z")

</div>

> [@approtocal](#):
>
> When use the Sketchup API, **SUModelCreateFromFileWithStatus** can return an error code named “SU\_ERROR\_SERIALIZATION”, can anyone let me know in what scenarios the API will return such error code?

It basically means an error occurred writing to or reading from file.

In the case of a read, it probably means that the file was corrupted or had a write error when it was written (or saved by the application.)

* * *

Here is a similar scenario (with another file write function) being discussed in the API Issue Tracker:

> <https://github.com/SketchUp/api-issue-tracker/issues/632>
>
> 1. SketchUp/LayOut Version: SDK 2019-2021, Python3
> 2. OS Platform: macOS 10.13,…10.15 tested both
> 
> Hello all. I’m in the process of updating the sketchup importer for blender to work with version 2.9.
> So far all seems to work but the textures. It seems that SUTextureWriteToFile always returns the error. SU\_ERROR\_SERIALISATION
> 
> I even tried not to use a tmp folder and used a folder that exists.
> 
> in python:
> 
> tex\_name = tex.name.split("/")\[-1\]
> temp\_dir = tempfile.gettempdir()
> skp\_fname = self.filepath.split("/")\[-1\].split(".")\[0\]
> temp\_dir += "/" + skp\_fname
> if not os.path.isdir(temp\_dir):
> os.mkdir(temp\_dir)
> temp\_file\_path = os.path.realpath(os.path.join(temp\_dir, tex\_name))
> skp\_log(f"Texture saved temporarily at {temp\_file\_path}")
> tex.write(temp\_file\_path)
> img = bpy.data.images.load(temp\_file\_path)
> img.pack()
> # os.remove(temp\_file\_path)
> shutil.rmtree(temp\_dir)
> 
> i do this and the cpython wrapper uses.
> 
> cdef class Texture:
> cdef SUTextureRef tex\_ref
>                 
> def \_\_cinit\_\_(self):
> self.tex\_ref.ptr = \<void\*\> 0
>                 
> def write(self, filename):
> py\_byte\_string = filename.encode('UTF-8')
> cdef const char\* file\_path = py\_byte\_string
> check\_result(SUTextureWriteToFile(self.tex\_ref, file\_path))
> 
> I have the strong suspicion this has to do with string -\> byte conversion done in the .pyx
> Python3 vs Python2 eventually.
> 
> source can be found here.
> https://github.com/arindam-m/pyslapi/tree/0.21
> 
> Same error in 2021SDKmac and 2020SDKmac and 2019SDKmac
> 
> Windows10 works as expected. So this could be a little/big endian problem.
> 
> regards u3real

---

<div class="post-metadata">

**Author:** ![approtocal](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@approtocal](https://forums.sketchup.com/u/approtocal)\
**Post date:** [April 28, 2021, 5:30am UTC](https://forums.sketchup.com/t/c-api-api-return-error-code-explaination/162214/4 "2021-04-28T05:30:24Z")

</div>

Thank you @DanRathbun , if the file is missing when reading (I can’t think how but just wondering if this happens), will it report SU\_ERROR\_SERIALIZATION as well?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 28, 2021, 7:17am UTC](https://forums.sketchup.com/t/c-api-api-return-error-code-explaination/162214/5 "2021-04-28T07:17:00Z")

</div>

Move or rename the test file and find out.
