title: Cannot Receive Unicode Value from input on Python-Flask
body: <p>My Sample Python Script is like this:</p>
  <pre><code># -*- coding: utf-8 -*-
  from flask import *
  
  app = Flask(__name__)
  
  
  @app.route('/', methods=['GET','POST'])
  def checkName():
      if request.method=='POST':
          namekh = request.form['KhmerName']
  
          print &quot;Khmer name is &quot;,namekh
          if isinstance(namekh.encode('utf8'), unicode):
              return render_template('hello.html', Name=namekh)
          else:
              namekh = 'Please enter khmer character only'
              return render_template('hello.html', Name=namekh)
  
  
      return render_template('hello.html')
  
  if __name__ == '__main__':
  
      app.run(debug=True)
  </code></pre>
  <p>From script above, I tried to received input value from form element name <code>KhmerName</code> on submit and check if it is a Unicode Character or not. Then I send it to display at my html markup <code>hello.html</code>.</p>
  <p>The html is look like this:</p>
  <pre><code>{% if Name %}
      &lt;p&gt;Hello, {{Name}} wellcome to mysite&lt;/p&gt;
  {% endif %}
  &lt;form class=&quot;form-horizontal&quot; action='' method='POST'&gt;
    &lt;div class=&quot;form-group&quot;&gt;
      &lt;label for=&quot;KhmerName&quot; class=&quot;col-sm-2 control-label&quot;&gt;Khmer Name:&lt;/label&gt;
      &lt;div class=&quot;col-sm-10&quot;&gt;
        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;KhmerName&quot; name=&quot;KhmerName&quot; placeholder=&quot;KhmerName&quot;&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-group&quot;&gt;
      &lt;div class=&quot;col-sm-offset-2 col-sm-10&quot;&gt;
        &lt;button type=&quot;submit&quot; class=&quot;btn btn-default&quot;&gt;Submit&lt;/button&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  <p>However, my problem is that if <code>KhmerName</code> is kind of None-Character is it working fine, yet it is an Unicode Character, it will return an error message</p>
  <pre><code>UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-4: character maps to &lt;undefined&gt;
  
  Traceback (most recent call last)
  File &quot;C:\Python27\lib\site-packages\flask\app.py&quot;, line 1997, in __call__
  return self.wsgi_app(environ, start_response)
  File &quot;C:\Python27\lib\site-packages\flask\app.py&quot;, line 1985, in wsgi_app
  response = self.handle_exception(e)
  File &quot;C:\Python27\lib\site-packages\flask\app.py&quot;, line 1540, in handle_exception
  reraise(exc_type, exc_value, tb)
  File &quot;C:\Python27\lib\site-packages\flask\app.py&quot;, line 1982, in wsgi_app
  response = self.full_dispatch_request()
  File &quot;C:\Python27\lib\site-packages\flask\app.py&quot;, line 1614, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File &quot;C:\Python27\lib\site-packages\flask\app.py&quot;, line 1517, in handle_user_exception
  reraise(exc_type, exc_value, tb)
  File &quot;C:\Python27\lib\site-packages\flask\app.py&quot;, line 1612, in full_dispatch_request
  rv = self.dispatch_request()
  File &quot;C:\Python27\lib\site-packages\flask\app.py&quot;, line 1598, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File &quot;F:\python\check Unicode\hello.py&quot;, line 12, in hello_world
  print &quot;Khmer name is &quot;,namekh
  File &quot;C:\Python27\lib\encodings\cp437.py&quot;, line 12, in encode
  return codecs.charmap_encode(input,errors,encoding_map)
  UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-4: character maps to &lt;undefined&gt;
  </code></pre>
  <p>What I did to check the Unicode here is by using <code>isinstance(namekh.encode('utf8'), unicode)</code>, so it should working (return true) because the type of <code>namekh</code> was already an <code>unicode</code> type if an input value was an unicode character. Yet, I had no idea why it return an error like above.</p>