So I am building a small flask-based search tool deployed on heroku to check what rankings universities can be found in. For this I am using fuzzywuzzy to go through lists of lists and returning the relevant rank.
@app.route('/results', methods=["POST"])
def results():
uniname = request.form["Name"]
with open("QS-2018-ASIA-clean.csv", encoding="ISO-8859-1") as f:
reader = csv.reader(f)
rankdata = [r for r in reader]
with open("THE_Ranking_Asia.csv", encoding="ISO-8859-1") as g:
reader1 = csv.reader(g)
rankdata1 = [r for r in reader1]
hit = process.extractOne(str(uniname), rankdata, scorer=fuzz.token_set_ratio)
hit1 = process.extractOne(str(uniname), rankdata1, scorer=fuzz.token_set_ratio)
return render_template('results.html', result1=str(hit[0]), result=str(hit[0][0]))
This throws an error which in my heroku app logs looks like this:
-File "/app/.heroku/python/lib/python3.6/site- packages/fuzzywuzzy/string_processing.py",
line 19, in replace_non_letters_non_numbers_with_whitespace
-return regex.sub(" ",a_string)
-TypeError: expected string or bytes-like object
This might be because the process.extractOne hit is a list? But the problem does not occur when I try this method in PyCharm. There he nicely prints out what I'm looking for (in this case with uniname = "Tokyo"):
print(hit) # (['14', 'THE UNIVERSITY OF TOKYO '], 100)
print(hit[0]) # ['14', 'THE UNIVERSITY OF TOKYO ']
print(hit[0][0]) # 14
Anyone have any idea why he throws the error in heroku flask app but not in PyCharm?
Based on a comment I tried checking fuzzywuzzy versions locally and in heroku. Doing this in heroku's python console throws the following error:
Thanks a lot!