title: php system, python and utf-8
body: <p>I have a python program running very well. It connects to several websites and outputs the desired information. Since not all websites are encoded with utf-8, I am requesting the charset from the headers and using <code>unicode(string, encoding)</code> method to decode (I am not sure whether its the appropriate way to do this but it works pretty well). When I run the python program I receive no ??? marks and it works fine. But when I run the program using php's <code>system</code> function, I receive this error:</p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\u0131' in position 41: ordinal not in range(128)
  </code></pre>
  
  <p>This is a python specific error but what confuses me is that I don't receive this error when I run the program using the terminal. I only receive this when I use php's <code>system</code> function and call the program from php. What may be the cause behind this problem?</p>
  
  <p>Here is a sample code:</p>
  
  <p>php code that calls python program:</p>
  
  <pre><code>system("python somefile.py $search") // where $search is the variable coming from an input
  </code></pre>
  
  <p>python code:</p>
  
  <pre><code>encoding = "iso-8859-9"
  l = "some string here with latin characters"
  print unicode("&lt;div class='line'&gt;%s&lt;/div&gt;" % l, encoding)
  # when I run this code from terminal it works perfect and I receive no ??? marks
  # when I run this code from php, I receive the error above
  </code></pre>