title: How to access a url if it has accented characters in it
body: <p>So I am working on a script that will automatically download and write data from a web service that delivers information in json format.  They are Canadian political parties and as such, accented characters pop up quite often.</p>
  
  <p>For instance, to access the data for candidates representing the party "Bloc Québécois", I need to access this url:</p>
  
  <p><a href="https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000&amp;party_name=Bloc%20Qu%C3%A9b%C3%A9cois" rel="nofollow">https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000&amp;party_name=Bloc%20Qu%C3%A9b%C3%A9cois</a></p>
  
  <p>Unfortunately, the simple solution of replacing the é's with e's does not work.</p>
  
  <p>so my script looks like this"</p>
  
  <pre><code>import urllib
  
  #party_name_list = ["Conservative", "Liberal", "NDP", "Green%20Party", "Bloc%20Québécois", "Forces%20et%20Démocratie", "Libertarian", "Christian%20Heritage"]
  party_name_list = ["Bloc%20Québécois"]
  
  for party_name in party_name_list:
      with urllib.request.urlopen(r"https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000&amp;party_name={}".format(party_name)) as url:
          with open(r"F:\electoral_map\20150914\candidates\candidates_{0}.json".format(party_name), "wb+") as f:
              f.write(url.read())
      print("finished {0}".format(party_name))
  print("all done")
  </code></pre>
  
  <p>I understand that this has something to do with utf-8 encoding, but I'm having a hard time wrapping my head around it and the other links I find here and on other websites are not helping.</p>
  
  <p>I tried adding a .encode('utf-8') in the urlopen call like this:</p>
  
  <pre><code>import urllib
  
  #party_name_list = ["Conservative", "Liberal", "NDP", "Green%20Party", "Bloc%20Québécois", "Forces%20et%20Démocratie", "Libertarian", "Christian%20Heritage"]
  party_name_list = ["Bloc%20Québécois"]
  
  for party_name in party_name_list:
      with urllib.request.urlopen(r"https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000&amp;party_name={}".format(party_name.encode(utf-8))) as url:
          with open(r"F:\electoral_map\20150914\candidates\candidates_{0}.json".format(party_name), "wb+") as f:
              f.write(url.read())
      print("finished {0}".format(party_name))
  print("all done")
  </code></pre>
  
  <p>But that just makes the file return empty because it is now calling the url:</p>
  
  <p><a href="https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000&amp;party_name=b" rel="nofollow">https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000&amp;party_name=b</a>'Bloc%20Qu\xc3\xa9b\xc3\xa9cois'</p>
  
  <p>Can someone please help me to understand how to make sense of this mess?</p>