Hi there i am coding in python trying to make a user friendly currency exchange app for a school project but have encountered and error with trying to decode json for the exchange rates. The code i'm using is:
import urllib.request
import json
(str) = "http://rate-exchange.appspot.com/currency?from=FRM&to=TO&q=AM";
(str) = (str.replace("FRM", "GBP"))
(str) = (str.replace("TO", "USD"))
url = (str.replace("AM", "20"))
f = urllib.request.urlopen(url)
data = (f.read(100))
print (data)
json_input = data
decoded = json.loads(json_input)
print ("conversion is: ", decoded["v"])
and the error that i am getting is:
b'{"to": "USD", "rate": 1.66215, "from": "GBP", "v": 33.243000000000002}'
Traceback (most recent call last):
File "C:\Users\jay\My Cubby\get qure.py", line 12, in <module>
decoded = json.loads(json_input)
File "C:\Python33\lib\json\__init__.py", line 309, in loads
return _default_decoder.decode(s)
File "C:\Python33\lib\json\decoder.py", line 352, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: can't use a string pattern on a bytes-like object
So i was just wondering if anyone had any ideas of how to fix this error? Or if anyone has seen this error before? Thanks in advance for any help J.Rymer