Quick post so Google might return something helpful for others hitting this error (Since I couldn’t find a post on the matter).
I hit this error using python on Mac OS X Leopard while writing a Cocoa based application and using minidom. I was doing a simple httplib.HTTPConnection request to a server and getting back XML in the body of the document. I was pulling the XML out using the response.read() method.
The server was setting the mime type and encoding correctly, and a type() call against the result showed it as a valid python string (<type ’str’>) and it was well formed XML. However, for some reason whenever I would feed it to minidom.parseString() Cocoa (or the PyObjC bridge or whatever) would die with the error “TypeError: Unsupported format string type”
I tried making the string an NSString thinking it was some Mac OS X implementation problem (various versions of NSString.alloc().initWithString_(str_response) setting encodings, copies of objects, etc), but it always caused the same error.
In the end, I simply gave up on the minidom library and used ElementTree instead (from xml.etree import ElementTree). ElementTree.fromstring(str_response) worked out of the box.
I hope this saves someone some time. It had me stumped for several hours since there is no other information beyond “Unsupported format string type” with the stack trace of:
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjCTools/AppHelper.py", line 235, in runEventLoop
I am still loving python though :)
Update
After working with ElementTree a bit more, I’ve discovered that the real culprit to this difficult-to-figure-out error message was likely due to the try/except statement around the method call. For example it was doing this:
try:
crazy.thing()
except Exception, e:
rsp = NSRunAlertPanel(
u"Bad Things",
e,
u"Let Me Try Again",
u"Quit",
None)
Any exception in the crazy.thing method will be masked by the “TypeError: Unsupported format string type” error when it tries to display e. To fix it I simply casted e to a string:
try:
crazy.thing()
except Exception, e:
rsp = NSRunAlertPanel(
u"Bad Things",
str(e),
u"Let Me Try Again",
u"Quit",
None)
So the real cause of my minidom problem is unknown since I’ve moved on to ElementTree. I am a bit disappointed in the error reporting with python Cocoa, but other than a few elusive and confusing errors it is sweet, and fun development platform.