[Answered ]-Syncdb error with Django under Windows (OpenKey error?)

2๐Ÿ‘

I had the SAME problem, but I resolved it differently. In case anybody else has this problem in the future and the above solution does not work for you, try editing mimetypes.py from this:

with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue

to this:

 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    if '\0' in subkeyname:                            #ADD THIS LINE
                        print("Skipping bad key: %s" % subkeyname)    #ADD THIS LINE
                        continue                                      #ADD THIS LINE
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue

Like I said, this answer is just for anybody else running into this problem with no success in implementing any other answer.

0๐Ÿ‘

Problem was with my Windows installation itself. There was some key that had invalid characters that mimetype.py was looping through as it looked for file associations.

Added the workaround to mimetype.py (+/- ln. 255):

**ln 252**
import re

**ln. 255**
pattern = re.compile('[\W{}\[\]_]+')
subkeyname = pattern.sub('',subkeyname)

Effectively, it stripes all none valid characters from subkeyname before it evaluates it as a registry key name.

Not the best, but it works. And probably is specific to this installation.

Leave a comment