title: Python - UnicodeEncodeError: 'charmap' codec can't encode characters in position 85-89: character maps to <undefined>
body: <p>I am trying to see if I can transfer the output of <code>urllib.request.urlopen()</code> to a text file just to look at it.  I tried decoding the output into a string so I can write into a file, but apparently the original output included some Korean characters that are not translating properly into the string.
  <br/>
  <br/>
  So far I have:</p>
  
  <pre><code>from urllib.request import urlopen
  
  openU = urlopen(myUrl)
  pageH = openU.read()
  openU.close()
  stringU = pageH.decode("utf-8")
  
  f=open("test.txt", "w+")
  f.write(stringU)
  </code></pre>
  
  <p>I do not get any errors until the last step at which point it says:  </p>
  
  <pre><code>Traceback (most recent call last):  
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;  
    File "C:\Users\Chae\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", line 19, in encode  
    return codecs.charmap_encode(input,self.errors,encoding_table)[0] 
  UnicodeEncodeError: 'charmap' codec can't encode characters in position 85-89: character maps to `&lt;undefined&gt;`
  </code></pre>
  
  <p>Is there a way to get the string to also include Korean or if not, how do I skip the characters causing problems and write the rest of the string into the file?</p>