title: Getting the correct encoding for strings and csv-files in Python
body: <p>I'm using mechanize in Python to grab some data from a website and send it new data.</p>
  
  <p>The thing is that the site is in French, so I get question marks in a diamond shape (�) instead of various characters such as éÉÀàùÙîû and others.</p>
  
  <p>I tried looking around on Google and StackOverflow and found various answers that didn't fix my problem. I've seen answers recommending trying one of the following lines:</p>
  
  <pre><code>myString = éÀî
  
  myString.encode('latin-1')
  myString.encode('iso-8859-1')
  
  unicode(myString, 'iso-8859-1')
  </code></pre>
  
  <p>but none of those seem to work.</p>
  
  <p>The two cases where I need this are when I read a csv file with accents and with hardcoded strings containing accents. For instance, here's what a line in the csv file looks like (actually ';' is the separator):</p>
  
  <pre><code>Adam Guérin;myemail@mail.com;555-5555;2011-02-05
  </code></pre>
  
  <p>The 'é' looks fine, but when I try to fill a textField on the website with mechanize and submit it, the 'é' now looks like '�' on the actual website.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This is my code for reading the data in the csv file:</p>
  
  <pre><code>subscriberReader = csv.reader(open(path, 'rb'), delimiter=';')
  subscribers = []
  
  for row in subscriberReader:
      subscribers.append(Subscriber(row[0], row[1], row[2]))
  </code></pre>
  
  <p>Then I send it to the website using mechanize:</p>
  
  <pre><code>self.br.select_form('aspnetForm')
  
  self.br.form['fldEmail'] = subscriber.email
  self.br.form['fldName'] = subscriber.name
  self.br.form['fldPhoneNum'] = subscriber.phoneNum
  
  self.br.submit()
  </code></pre>
  
  <p>I tried various ways to encode the characters, but I guess I'm not doing it correctly. I'll be glad to try anything that gets suggested in the answers / comments.</p>
  
  <p>As for the website, it doesn't specify which encoding it is using in the header.</p>