Index: pyyaml/trunk/ext/_yaml.pyx
===================================================================
--- pyyaml/trunk/ext/_yaml.pyx	(revision 350)
+++ pyyaml/trunk/ext/_yaml.pyx	(revision 361)
@@ -955,9 +955,10 @@
         self.stream = stream
         self.dump_unicode = 0
-        try:
-            if stream.encoding:
+        if PY_MAJOR_VERSION < 3:
+            if hasattr(stream, 'encoding'):
                 self.dump_unicode = 1
-        except AttributeError:
-            pass
+        else:
+            if hasattr(stream, u'encoding'):
+                self.dump_unicode = 1
         self.use_encoding = encoding
         yaml_emitter_set_output(&self.emitter, output_handler, <void *>self)    
