I am trying to learn how to take a body with data in the GET method, but for some reason nothing comes from me.
Here is the code:
from flask import Flask, request app = Flask(__name__) @app.route('/test') def get_test_data(): print('\nrequest:') print(request) print('request.data:') print(request.data) And here is the test code:
import unittest from flask import url_for from proba import app class ProbaTest(unittest.TestCase): def setUp(self): self.app_ctx = app.app_context() self.app_ctx.push() self.client = app.test_client() def tearDown(self): self.app_ctx.pop() def test(self): self.client.get(url_for('get_test_data'), data={'username' : 'user1', 'password' : 'pass1'}) if __name__ == '__main__': unittest.main(verbosity=2) I receive:
(env) d:\Projects\python-workspace\proba>python manage.py test test (proba_test.ProbaTest) ... request: <Request 'http://localhost/test' [GET]> request.data: b'' ok My main goal: To give out information on my resources only to those who are registered.
To do this, I write a decorator, which checks the username and password passed in the request. And this is a minimal example of repeating my situation.
Please tell me what am I doing wrong?
UPD : In the comments it was said that the body cannot be sent to GET. There is a discussion on this topic in the English version of stackoverflow: HTTP GET with request body