title: How can a string (taken from a python wsgi environ) be different when iterating over its chars?
body: <p>We have recently come across a situation where iterating over a string (e.g. <code>list(some_string)</code>) gives something completely different than printing <code>some_string</code> directly. How can this happen?</p>
  <p>Some background: We are running a python web application on IIS using wfastcgi, with the application server behind a load balancer. We had some issues with both the application server's internal and the load balancer's external host turning up in different parts of the application, so to narrow it down we wrote a small wsgi server to take a look at what exactly is passed inside.</p>
  <p>This is the module, again run using wfastcgi on IIS:</p>
  <pre><code># test-wsgi.py
  
  def application(environ, start_response):
      status = '200 OK'
      headers = [('Content-type', 'text/plain; charset=utf-8')]
  
      body = 'Host: {}\n\n'.format(environ['HTTP_HOST']).encode('utf-8')
  
      chars = list(environ['HTTP_HOST'])
      body += 'Host by char: {}\n\n'.format(chars).encode('utf-8')
      
      start_response(status, headers)
      return [body]
  </code></pre>
  <p>And, behold the madness, this is the response:</p>
  <pre><code>Host: pretty-domain.com
  
  Host by char: ['i', 'n', 't', 'e', 'r', 'n', 'a', 'l', '.', 'h', 'o', 's', 't', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm']
  </code></pre>
  <p>We get the same results with other methods of iterating over the string, like for loops or list comprehensions, or just using <code>len()</code>.</p>
  <p>Apart from the question of what causes these specific values to turn up in our setup - how can this happen in python at all?</p>
  <p>This is on IIS 10, python 3.6.8 and wfastcgi 3.0.0.</p>