title: TypeError: the JSON object must be str, not 'bytes' - Python - fixer.io
body: <p>I have this code:</p>
  
  <pre><code>from flask import Flask, flash, redirect, render_template, request, session, abort
  import os
  import json
  from urllib.request import urlopen
  
  tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
  app = Flask(__name__, template_folder=tmpl_dir)
  
  def getExchangeRates():
      rates = []
      response = urlopen('https://data.fixer.io/api/latest?access_key=my_key')
      data = response.read()
      rdata = json.loads(data, parse_float=float)
  
      rates.append( rdata['rates']['USD'] )
      rates.append( rdata['rates']['GBP'] )
      rates.append( rdata['rates']['HKD'] )
      rates.append( rdata['rates']['AUD'] )
      return rates
  
  @app.route("/")
  def index():
      rates = getExchangeRates()
      return render_template('test.html',**locals())      
  
  @app.route("/hello")
  def hello():
      return "Hello World!"
  </code></pre>
  
  <p>But it throws me this:</p>
  
  <pre><code>Traceback (most recent call last):
  File "/home/kristian/.virtualenvs/usio_flask/lib/python3.4/site-packages/flask/app.py", line 2292, in wsgi_app
  response = self.full_dispatch_request()
  File "/home/kristian/.virtualenvs/usio_flask/lib/python3.4/site-packages/flask/app.py", line 1815, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File "/home/kristian/.virtualenvs/usio_flask/lib/python3.4/site-packages/flask/app.py", line 1718, in handle_user_exception
  reraise(exc_type, exc_value, tb)
  File "/home/kristian/.virtualenvs/usio_flask/lib/python3.4/site-packages/flask/_compat.py", line 35, in reraise
  raise value
  File "/home/kristian/.virtualenvs/usio_flask/lib/python3.4/site-packages/flask/app.py", line 1813, in full_dispatch_request
  rv = self.dispatch_request()
  File "/home/kristian/.virtualenvs/usio_flask/lib/python3.4/site-packages/flask/app.py", line 1799, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File "app/app.py", line 23, in index
  rates = getExchangeRates()
  File "app/app.py", line 13, in getExchangeRates
  rdata = json.loads(data, parse_float=float)
  File "/usr/lib/python3.4/json/__init__.py", line 312, in loads
  s.__class__.__name__))
  TypeError: the JSON object must be str, not 'bytes'
  </code></pre>
  
  <p>The offending line is this one:</p>
  
  <pre><code>rdata = json.loads(data, parse_float=float)
  </code></pre>
  
  <p>I'm just trying to get some rates from <code>fixer.io</code> API, any ideas?</p>
  
  <p>if <strong>name</strong> == "<strong>main</strong>":
      app.run()</p>