I am trying to download a dataset using the following code from a publicly available platform that was used before for the same purpose. However, I am not sure why I get this error, that is, whether because of an error in code or some changes in the website's (hatebase) API. Any suggestions would be very helpful. Thank you.
import json
import requests
import pandas as pd
from hatebase import HatebaseAPI
key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA" # this is the key
filepath = "/dictionary.csv"
hatebase = HatebaseAPI({"key": key})
filters = {"language": "eng"}
format = "json"
# initialize list for all vocabulary entry dictionaries
eng_vocab = []
response = hatebase.getVocabulary(filters=filters, format=format)
pages = response["number_of_pages"]
# fill the vocabulary list with all entries of all pages
# this might take some time...
for page in range(1, pages+1):
filters["page"] = str(page)
response = hatebase.getVocabulary(filters=filters, format=format)
eng_vocab.append(response["result"])
# create empty pandas df for all vocabulary entries
df_eng_vocab = pd.DataFrame()
# fill df
for elem in eng_vocab:
df_eng_vocab = df_eng_vocab.append(elem)
# reset the df index
df_eng_vocab.reset_index(drop=True, inplace=True)
# saving the file to csv
df_eng_vocab.to_csv(filepath)
The error I get is the following
Please check your API-Key, Authentication did nod respond with a token.
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-60-de9970a761e5> in <module>
7 #filepath = "/dictionary.csv"
8
----> 9 hatebase = HatebaseAPI({"key": key})
10 filters = {"language": "eng"}
11 format = "json"
~\Anaconda3\lib\site-packages\hatebase\__init__.py in __init__(self, settings)
37 self.debug = settings["debug"]
38
---> 39 self.authenticate()
40
41 def authenticate(self):
~\Anaconda3\lib\site-packages\hatebase\__init__.py in authenticate(self)
57 print("Please check your API-Key, Authentication did nod respond with a token.")
58
---> 59 if token is not None:
60 self.token = response.json()["result"]["token"]
61 else:
UnboundLocalError: local variable 'token' referenced before assignment
tokenwith default valueNone. OR maybe it couldn't get token from server and it didn't set default valuetoken = None. Porbably you will have to digg in source code to checktoken. OR if this module has GitHub then check on GitHub if it has some fix.