SHARE
TWEET

Untitled

a guest Apr 26th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BASE_URL = "http://api.nbp.pl/api/exchangerates/rates/a"
  2. code = 'GBP'
  3. start_date = '2018-02-10'
  4. end_date = '2019-01-20'
  5.  
  6. def get_values(code: str, start_date: str, end_date: str) -> dict:
  7.     """ Function takes currency 'code', 'start_date' and 'end_date' of searching data
  8.        and package rates into the dictionary"""
  9.     url = f"{BASE_URL}/{code}/{start_date}/{end_date}/?format=json"
  10.     response = requests.get(url)
  11.     rates = json.loads(response.text)
  12.     return {rate["effectiveDate"]: rate["mid"] for rate in rates["rates"]}
  13.  
  14. values_dictionary = get_values(code, start_date, end_date)
  15.  
  16.  
  17. -------- ZWRACANY BŁAD W KONSOLI --------
  18.  
  19. Traceback (most recent call last):
  20.   File "nbp.py", line 72, in <module>
  21.     main()
  22.   File "nbp.py", line 67, in main
  23.     values_dictionary = get_values(code, start_date, end_date)
  24.   File "nbp.py", line 33, in get_values
  25.     rates = json.loads(response.text)
  26.   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
  27.     return _default_decoder.decode(s)
  28.   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 340, in decode
  29.     raise JSONDecodeError("Extra data", s, end)
  30. json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top