Forums

Flask + getJSON() problem

Hi! I'm doing a little site for a university work and I have a issue that I can't really figure out... I'm working with Flask and getJSON() and the problem is I can't pass a long string variable to my Python code (for long I mean kind of 800 lines of a JSON file). This is working on my local machine, so I think it's maybe a PythonAnywhere issue? Can you give me a hand? Thank you in advance!

What do you mean by "pass"? From where? How?

Hi, Glenn! I mean passing a long string variable as URL argument. Firefox doesn't give me any error (just doesn't do anything!), but today I tested this in Chrome and I got 414 (Request-URI Too Large) error. Also, I added this functions to my index.html so you can easily see what's going on when you load the page and reproduce the error:

function test_short() {
  $.getJSON($SCRIPT_ROOT + '/_test', {
    a: short
  }, function(data) {
    var msg = data.result;

    console.log('test_short');
  });

  return false;
}

function test_long() {
  $.getJSON($SCRIPT_ROOT + '/_test', {
    a: long
  }, function(data) {
    var msg = data.result;

    console.log('test_long');
  });

  return false;
}

test_short();
test_long();

short and long variables are defined above in my code (they are a little long, so I doesn't posted them here). In addition, in my Python code you can see this:

@app.route('/_test')
def test():
    return jsonify(result='/_test')

At my Web console, only the test_short message is printed out.

Servers and browsers are pretty inconsistent about the length of URIs. You can sidestep all of that by passing your data in the body of a POST.

Thanks!