I have a flask server and nginx handling the incoming connections. When I call a specific method of the flask api using https it works fine, the problem is when nginx redirects from http to https and the data included in the python call gets lost.
NGINX config file:
server {
server_name myurl.com;
listen 80;
location / {
return 301 https://myurl.com$request_uri;
}
}
server {
server_name myurl.com;
listen 443 ssl;
add_header Strict-Transport-Security "max-age=31536000";
ssl_certificate /etc/letsencrypt/live/myurl.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myurl.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
include uwsgi_params;
uwsgi_pass flask_server:5555;
}
}
Python call:
from requests import get
token = {'token': 'thetoken1234'}
data={'kms': '80000'}
response = get('http://myurl.com/evaluate_car', headers=token, data=data).json()
Calling the https version of the url works fine but in the http case the "kms" variable in the data dictionary is getting lost.
What I need to include in the NGINX config file to keep this data dictionary?
GETas method? Passing data is usually done throughPUTget(…, data=data)causes, the data is part of the URL – and you're specifically overwriting that URL with your redirect, so this is all correct from my perspective. Easy solution: don't use GET for something which is usually done using PUT.