Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BASE_URL = "http://api.nbp.pl/api/exchangerates/rates/a"
- code = 'GBP'
- start_date = '2018-02-10'
- end_date = '2019-01-20'
- def get_values(code: str, start_date: str, end_date: str) -> dict:
- """ Function takes currency 'code', 'start_date' and 'end_date' of searching data
- and package rates into the dictionary"""
- url = f"{BASE_URL}/{code}/{start_date}/{end_date}/?format=json"
- response = requests.get(url)
- rates = json.loads(response.text)
- return {rate["effectiveDate"]: rate["mid"] for rate in rates["rates"]}
- values_dictionary = get_values(start_date, end_date, code)
- -------- ZWRACANY BŁAD W KONSOLI --------
- Traceback (most recent call last):
- File "nbp.py", line 72, in <module>
- main()
- File "nbp.py", line 67, in main
- values_dictionary = get_values(code, start_date, end_date)
- File "nbp.py", line 33, in get_values
- rates = json.loads(response.text)
- File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
- return _default_decoder.decode(s)
- File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 340, in decode
- raise JSONDecodeError("Extra data", s, end)
- json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement