I’m trying to port code from
from javascript to python (flask) for my backend app but I’m having issues with form-data being null.
from flask import Flask, request, jsonify
import requests
app = Flask(__name__)
def get_client_ip(req):
return req.headers.get('X-Forwarded-For', request.remote_addr)
def check_ip_from_ipquery(ip):
try:
response = requests.get(f"https://api.ipquery.io/{ip}")
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
return None
@app.route('/submit', methods=['POST'])
def submit():
form_data = request.json
form_ip = form_data.get('ip-query')
webrtc = form_data.get('webrtc-ip')
timezone = form_data.get('timezone')
client_ip = get_client_ip(request)
ip_query_data = check_ip_from_ipquery(client_ip)
if ip_query_data and 'risk' in ip_query_data:
is_proxy = ip_query_data['risk'].get('is_proxy', False)
is_datacenter = ip_query_data['risk'].get('is_datacenter', False)
is_vpn = ip_query_data['risk'].get('is_vpn', False)
if is_proxy or is_datacenter or is_vpn:
return jsonify({
"message": "Signup blocked.",
}), 403
return jsonify({"token":"TOKEN"}), 201
if __name__ == '__main__':
app.run(port=3001)