title: python popen special characters not parsing file
body: <p>I am having issues with non ASCII characters. </p>
  
  <p>I am using python 2.7.3</p>
  
  <pre><code>python -V
  Python 2.7.3
  </code></pre>
  
  <p>I installed <a href="http://pymediainfo.readthedocs.org/en/latest/" rel="nofollow">http://pymediainfo.readthedocs.org/en/latest/</a></p>
  
  <p>via</p>
  
  <pre><code>easy_install pymediainfo
  </code></pre>
  
  <p>imported as below</p>
  
  <pre><code>from pymediainfo import MediaInfo
  
  media_info = MediaInfo.parse(os.path.join(path, to, file))
  </code></pre>
  
  <p>using this with ascii characters is fine</p>
  
  <p>for debugging I printed the 'command' from:</p>
  
  <pre><code>/usr/local/lib/python2.7/dist-packages/pymediainfo-1.3.5-py2.7.egg/pymediainfo/__init__.py
  </code></pre>
  
  <p>the class that 'runs' the mediainfo command in /usr/local/lib/python2.7/dist-packages/pymediainfo-1.3.5-py2.7.egg/pymediainfo/<strong>init</strong>.py</p>
  
  <pre><code>ENV_DICT = {
      "PATH": "/usr/local/bin/:/usr/bin/",
      "LD_LIBRARY_PATH": "/usr/local/lib/:/usr/lib/"}
  
  @staticmethod
  def parse(filename, environment=ENV_DICT):
      command = ["mediainfo", "-f", "--Output=XML", filename]        
      print command
      print repr(command)
      fileno_out, fname_out = mkstemp(suffix=".xml", prefix="media-")
      fileno_err, fname_err = mkstemp(suffix=".err", prefix="media-")
      fp_out = os.fdopen(fileno_out, 'r+b')
      fp_err = os.fdopen(fileno_err, 'r+b')
      p = Popen(command, stdout=fp_out, stderr=fp_err, env=environment)
      p.wait()
      fp_out.seek(0)
      xml_dom = MediaInfo.parse_xml_data_into_dom(fp_out.read())
      fp_out.close()
      fp_err.close()
      return MediaInfo(xml_dom)
  </code></pre>
  
  <p>both print and print repr() display:</p>
  
  <pre><code>['mediainfo', '-f', '--Output=XML', "/mnt/path/Long 73\xc2\xb0 58' W.avi"]
  </code></pre>
  
  <p>the filename is:</p>
  
  <pre><code>Long 73° 58' W.avi
  </code></pre>
  
  <p>Looking at a UTF-8 table \xc2\xb0 corresponds to °</p>
  
  <p>I am aware this might just be just the console not interpreting the encoding as it should but the output of mediainfo is just</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Mediainfo version="0.7.58"&gt;
  &lt;/Mediainfo&gt;
  </code></pre>
  
  <p>which means "file not found"</p>
  
  <pre><code>os.path.isfile(os.path.join(path, to, file))
  </code></pre>
  
  <p>returns true for these files</p>
  
  <p>and in bash using</p>
  
  <pre><code>mediainfo -f --Output=XML "/path/to/file"
  </code></pre>
  
  <p>works</p>
  
  <p>i have goggled and searched around and cannot see the answer.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>
  
  <p>UPDATE</p>
  
  <p>I used this new test script</p>
  
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  import sys
  import os
  import subprocess as sub
  root = "/mnt/path"
      for rootfldr in sorted(os.listdir(root)):
          if os.path.isfile(os.path.join(root, rootfldr)):
              command = ['mediainfo', '-f', '--Output=XML', rootfldr]
              aa = sub.Popen(command, stdout=sub.PIPE, stderr=sub.PIPE, stdin=sub.PIPE)
              result = aa.communicate()[0]
              print rootfldr
              print result
  </code></pre>
  
  <p>And the results were fine (some of then had non ASCII chars).</p>
  
  <p>I then decided to change (from the pymedinfo parse function):</p>
  
  <pre><code>p = Popen(command, stdout=fp_out, stderr=fp_err, env=environment)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>p = Popen(command, stdout=fp_out, stderr=fp_err)
  </code></pre>
  
  <p>and the problem was solved</p>
  
  <p>I am guessing that something is missing and or wrong from</p>
  
  <pre><code>ENV_DICT = {
      "PATH": "/usr/local/bin/:/usr/bin/",
      "LD_LIBRARY_PATH": "/usr/local/lib/:/usr/lib/"}
  </code></pre>