Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

2.1K
Views
Frasco - Solicitud incorrecta El navegador (o proxy) envió una solicitud que este servidor no pudo entender

Estoy tratando de cargar un archivo e ingresar una tarea de datos en mi MongoDB usando un matraz, pero tuve este error cuando llené mi formulario y cargué la imagen:

Solicitud incorrecta El navegador (o proxy) envió una solicitud que este servidor no pudo entender.

mi código HTML

 <form class="form-check form-control" method="post" enctype="multipart/form-data" action="{{ url_for('index') }}"> <label>Full Name*</label></td> <input name="u_name" type="text" class="text-info my-input" required="required" /> <label>Email*</label> <input name="u_email" type="email" class="text-info my-input" required="required" /> <label>Password*</label> <input name="u_pass" type="password" class="text-info my-input" required="required" /> <label>Your Image*</label> <input name="u_img" type="file" class="text-info" required="required" /></td> <input name="btn_submit" type="submit" class="btn-info" /> </form>

& mi código python:

 from flask import Flask, render_template, request, url_for from flask_pymongo import PyMongo import os app = Flask(__name__) app.config['MONGO_DBNAME'] = 'flask_assignment' app.config['MONGO_URI'] = 'mongodb://<user>:<pass>@<host>:<port>/<database>' mongo = PyMongo(app) app_root = os.path.dirname(os.path.abspath(__file__)) @app.route('/', methods=['GET', 'POST']) def index(): target = os.path.join(app_root, 'static/img/') if not os.path.isdir(target): os.mkdir(target) if request.method == 'POST': name = request.form['u_name'] password = request.form['u_pass'] email = request.form['u_email'] file_name = '' for file in request.form['u_img']: file_name = file.filename destination = '/'.join([target, file_name]) file.save(destination) mongo.db.employee_entry.insert({'name': name, 'password': password, 'email': email, 'img_name': file_name}) return render_template('index.html') else: return render_template('index.html') app.run(debug=True)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El error allí es el resultado de un BadRequestKeyError debido al acceso a una clave que no existe en request.form .

 ipdb> request.form['u_img'] *** BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Los archivos cargados se codifican en request.files y no en request.form dictionary. Además, debe perder el ciclo porque el valor ingresado en u_img es una instancia de FileStorage y no es iterable .

 @app.route('/', methods=['GET', 'POST']) def index(): target = os.path.join(app_root, 'static/img/') if not os.path.isdir(target): os.makedirs(target) if request.method == 'POST': ... file = request.files['u_img'] file_name = file.filename or '' destination = '/'.join([target, file_name]) file.save(destination) ... return render_template('index.html')
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!