Why can I not import an .mp3 file through Python scripting? I'm following this tutorial and I'm about 29 minutes in. I'm using the .mp3 mentioned in the tutorial. Here's my latest .blend...

My script will create a single cube and switch the window context to GRAPH_EDITOR, but then crashes out with the error, "unsupported audio format". Error text follows...


  Traceback (most recent call last): File "J:\My
  Documents\Desktop\Motion Graphics\cgCookieVisualiser01001Rev.blend
  \Text", line 34, in  File "E:\Program Files\Blender
  Foundation\Blender\2.70\scripts\modules\bpy\ops .py", line 188, in
  call ret = op_call(self.idname_py(), None, kw) RuntimeError: Error: Unsupported audio format
  
  Error: Python script fail, look in the console for now...


It seems strange that the .mp3 wouldn't import via script. Has anybody a suggestion on how I should tackle this?
I just tested your file with one of my own .mp3s and found two problems:


The path contains backslashes. This is standard in Windows, but has special meaning in many programming languages. The backslash means that the following character should not be interpreted as a normal character but as a control character (like \n stands for new-line and \a will make a beeping sound). Your path contains a \0 which (at least in C) is interpreted as 'End of String'. This messes up your path: When the string ends there, the file is actualy a folder and has no extension. Thus it can not be recognized as a supported audio format.
There are two possible solutions:


Replace all backslashes with forward slashes / and make a Unix-style path
Replace them with double backslashes \\. The first backslash removes the special meaning of the second backslash and makes it a normal character again.

You wrote true instead of True (with a capital letter) in line 37. This is a minor issue, but causes an error when you run the script ;)


After that your script runs fine.

EDIT :
I just found another mehtod to use string literals with backslashes. If you write

mypath = r"C:\Path\To\Some\File.mp3"


the r in front of the string literal tells python that this is a so-called raw string literal. This will preserve the backslashes and not use them to create control characters.