Path with french letters [SOLVED]

On 19/01/2015 at 14:29, xxxxxxxx wrote:


Thanks for all the support -

i have a bug in my plugin — reported from a french user

i try to write a file to a path but with  a special letter in his username - I get an error with that path

Sébastian = c:\users\sÇbastien\

how can I prevent it?

path =
path = os.path.join(path, "StagePlugin/")
path = os.path.normpath(path)

On 19/01/2015 at 17:00, xxxxxxxx wrote:

Hi conner,

I had to edit the message because I got some advice to give an answer that covers all of C4D / Python's UTF-8 character set.

This exact problem is why I don't spell my last name with the "é" inside most software ("Gaspé"), as the computer world is several years away from fully supporting Unicode, let alone IBM PC extended ASCII, and some try but get it all mixed up across the different encodings.  It's one of those 'weakest link' issues.

I managed to reproduce the problem and found what should be the solution in this case.  C4D supports UTF-8, and Python's str type can be encoded in UTF-8 also.

I had to add to the path the "é" as u"\u00E9" to simulate it coming out of the path preferences call, even if the call results in 'range compliant' symbols.  The code you provided will display it corrupted with the two symbols you report.  By adding "path.decode("utf-8")" it will display it as it should, the e-acute ("e accent aigu" in French).  I'm spelling it out explicitly for anyone who might be seeing the é symbol as garbage in their particular browser, however unlikely.

Here's the code itself:

import c4d  
import os  
def main() :  
  path =  
  path = path.decode("utf-8") + u"\u00E9"  
  path = os.path.join(path, "StagePlugin/")  
  path = os.path.normpath(path)  
  print path  

This link shows you another example in the Python documentation.

This link explains the encoding / decoding issue specifically.

I hope that helps solve the problem!

Joey Gaspe
SDK Support Engineer

On 26/01/2015 at 10:34, xxxxxxxx wrote:

Hi conner,

I'd like to know if my reply helped you?  I'm curious because I can't repro exactly the issue, only simulate it, so a response would put to rest any doubts we have on the C4D side that everything is OK.


Joey Gaspe
SDK Support Engineer

On 26/01/2015 at 15:17, xxxxxxxx wrote:

I try to add the code but get an error


Traceback (most recent call last) :
  File "'stage.pyp'", line 13358, in <module>
  File "'stage.pyp'", line 1238, in Strukturcheck
  File "'stage.pyp'", line 1120, in readPreferences
TypeError: argument 2 must be str or, not unicode

line 1120 -         if hf.Open(ident=key, filename=path, mode=c4d.FILEOPEN_READ, error_dialog=c4d.FILEDIALOG_ANY) :

On 26/01/2015 at 15:40, xxxxxxxx wrote:

You should encode the path in UTF-8.

path = path.encode('utf-8')

On 27/01/2015 at 07:47, xxxxxxxx wrote:

Hi conner,

Thanks for trying it.  I can speculate that what NiklasR is proposing might work (changing from 'decode' to 'encode'), since you're getting the accent from GeGetC4DPath(), not the script itself, which is as close as we could get to reproduce the issue quickly (while adding the accent with  + u"\u00E9").  Either way, please let us know if either works, or if you're still stuck.  If you're still stuck, please include the exact code and errors you get, as their variance may give us clues.


Joey Gaspe
SDK Support Engineer

On 02/02/2015 at 12:37, xxxxxxxx wrote:

Due to several days of inactivity, and the feeling that the proposed fix should work, I'll close this topic as solved.

Joey Gaspe
SDK Support Engineer