title: UnicodeDecodeError in Python when reading a file, how to ignore the error and jump to the next line?
body: <p>I have to read a text file into Python. The file encoding is:</p>
  
  <pre><code>file -bi test.csv 
  text/plain; charset=us-ascii
  </code></pre>
  
  <p>This is a third-party file, and I get a new one every day, so I would rather not change it. The file has non ascii characters, such as Ö, for example. I need to read the lines using python, and I can afford to ignore a line which has a non-ascii character.</p>
  
  <p>My problem is that when I read the file in Python, I get the UnicodeDecodeError when reaching the line where a non-ascii character exists, and I cannot read the rest of the file.</p>
  
  <p>Is there a way to avoid this. If I try this:</p>
  
  <pre><code>fileHandle = codecs.open("test.csv", encoding='utf-8');
  try:
      for line in companiesFile:
          print(line, end="");
  except UnicodeDecodeError:
      pass;
  </code></pre>
  
  <p>then when the error is reached the for loop ends and I cannot read the remaining of the file. I want to skip the line that causes the mistake and go on. I would rather not do any  changes to the input file, if possible.</p>
  
  <p>Is there any way to do this?
  Thank you very much.</p>