0

I am doing a song search engine as a project and everything works fine except when I run the program from 2 different computers the data sent to each computer is mixed with the data sent to the other computer

I've tried separating the users with variables in sessions but the variable is much bigger than the max value a session variable can hold. I've tried also making a different URL based on the request but for some reason it sends a 404 error.

This is the python code relevant

@app.route("/", methods=['GET','POST'])
def index():
    global str_request
    global search_done
    global songs
    global already_requested
    already_requested=False
    api_connection=connected_to_internet()
    print(api_connection)
    if api_connection:
        if request.method == 'POST':
            search_request = request.form.getlist('search[]')
            str_request=turn_list_to_str(search_request)
            str_request=str_request.replace(' ','%20')
            print ("/result/"+str_request)
            search_request=arrange_request(search_request)
            print(search_request)
            songs=[]
            data=search_api(search_request)
            search_done=False
            if data!=None:
                for hit in data:
                    songs.append(Song(hit['result']['full_title'],hit['result']['primary_artist']['name'],hit['result']['url'],hit['result']['song_art_image_thumbnail_url']))          
        return render_template('layout.html')
    else:
        return render_template('connection.html')


@app.route("/result/"+str_request)
def result():
    global songs
    return render_template("result.html",songs=songs)

this is the js code relevant

    $(document).ready(function(){
      $("#search_button").click(function(){
        btn=document.getElementById("search_button");
        btn.disabled=true;
        var $loader = $("<div />");
        $loader.addClass('loader');
        $loader.appendTo("body");
        var search_result=arrangeTag();
        //post https://lyritag.xyz/
        $.post("http://localhost/",
        {
            "search":search_result
        },function(){
          //var user_request = '<%=Session["user_request"]%>';
          //alert(user_request);
            for(var i = 0; i < search_result.length; i++){
                console.log(search_result[i])
            }
          location.replace("/result/"+search_result);
        })
      });
    });

Both the URL and the app.route of the result are the same but It returns a 404 error. Any other solution will be great as well.

  • Possible duplicate of [Are global variables thread safe in flask? How do I share data between requests?](https://stackoverflow.com/questions/32815451/are-global-variables-thread-safe-in-flask-how-do-i-share-data-between-requests) – djnz Jun 24 '19 at 22:42
  • No that doesn't answer my question – MichaelCracker Jun 24 '19 at 23:32

0 Answers0