vnoelifant / charity-finder

3 stars 0 forks source link

2 api function #3

Closed vnoelifant closed 1 year ago

vnoelifant commented 1 year ago

Basic data retrieval in home page from get themes, and get featured projects in https://www.globalgiving.org/api/methods/. Utilized xmltodict for viewing data as dictionaries, since I am looking at the following error when I try to add headers to use JSON. When I uncomment these lines in charity_api.py.


    # TODO: DEBUG JSON Decode error when lines below uncommented:

    # headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}

    # response = requests.get(url, params=params, headers=headers)

    # return response.json()

I receive the following error:

(charity-finder) ronnienm08@DESKTOP-94KD1T3:~/charity-finder$ python charity_finder/charity_api.py 
URL:  https://api.globalgiving.org/api/public/projectservice/themes
Traceback (most recent call last):
  File "/home/ronnienm08/.local/share/virtualenvs/charity-finder-eKohszMN/lib/python3.9/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ronnienm08/charity-finder/charity_finder/charity_api.py", line 36, in <module>
    data = get_charity_data("/themes")
  File "/home/ronnienm08/charity-finder/charity_finder/charity_api.py", line 30, in get_charity_data
    return response.json()
  File "/home/ronnienm08/.local/share/virtualenvs/charity-finder-eKohszMN/lib/python3.9/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)