A Division-by-zero Error?

Hello all! I’m working on a personal project and I’m running into 2 errors which occur at the same spot in my code.

#1: Division by zero: This error is caused because I’m sending a paragraph of data from the frontend to the backend and it’s not arriving. Since it never arrives, the numbers are null and it tries to divide null by zero. (This error happens sometimes on my local machine, but every time on Heroku.)

#2: CSRF: I’m trying to protect the second API endpoint using CSRF, but I’m not quite sure how to do it. This might be effecting the first error.

Project:

Online version:
https://songfeels.herokuapp.com

Pseudocode:
-User searches for song. File: components/Main.js on frontend.
-class SongView get() runs a query on api, sends back lyrics. File: backend/views.py on backend.
-Page renders a list of songs. File: components/SearchResults.js on frontend.
-User chooses a song to analyze. axios.post sends the original_lyrics. File: components/Main.js again on frontend.
(This is where both errors are causing problems)
-class AnalyzeView post() should storerequest.body.decode data as post_data. Sometimes it works, sometimes it doesn’t. File: backend/views.py again on backend.

Any suggestions how to fix either problem?

I solved the first error! When Python ran the first query, it was importing and opening my CSV file and then forgetting about it. When the second query ran, it tried to access the variable with CSV file, couldn’t find it, and the calculations weren’t running.

So now I am importing the CSV inside class AnalyzeView, in the function that uses it, and haven’t had any errors since then.

I’m going to try and tackle the CSRF stuff now & see if I can figure it out too!