1

Code:

def reqURL():
    request = urllib.request.urlopen('https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat')
    html = request.read()
    html = html.decode(encoding="utf-8", errors="ignore")
    print(html)

Error:

UnicodeEncodeError: 'charmap' codec can't encode character '\u017d' in position 468663: character maps to <undefined>

Question: I read the docs and put errors="ignore" in my code but it isn't working! Why?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Marcel
  • 199
  • 1
  • 18
  • 1
    You have an *Encode* error, caused by trying to print Unicode text to a Windows console that can't handle your text. – Martijn Pieters Jan 03 '17 at 19:38
  • 1
    This is why the traceback is important; look at that too, not just the exception you get. The traceback would have shown you that the error takes place on the `print(html)` line, not the line with the `html.decode()` call. – Martijn Pieters Jan 03 '17 at 19:43
  • Thanks a lot @MartijnPieters . I find a solution on this Post (http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how) - Just type "chcp 65001" in the windows console and it is working. – Marcel Jan 03 '17 at 19:53
  • Take into account that your console font still may cause issues too. Not all fonts can handle the wide array of text Unicode can encode. – Martijn Pieters Jan 03 '17 at 19:54

0 Answers0