我在debian vm上有相同的dockerized flask应用程序,没有这个问题。它只会在我的RPI 3B +上引发错误400 Bad Request。两者都限于一个内核和1 GB的内存。 我不明白为什么它只在pi上抛出400。即使使用try-encapsulation,好像由于访问request.form而崩溃。带有和不带有get(){request.form.get('data',False)}
我正在此容器中运行python3。
只有在文件大小超过50 kb左右,工作1 kb的文件,以'工作'的形式上载无文件,但较大的文件引发错误400时才会发生。文件上载旨在与.xlsx文件一起使用通常大于50kb。
/ var / log / apache2 / error根本不会记录此错误。
eprint是我发现写给stderr的函数,是我快速调试该应用程序死于何处的方法。
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
我已经看过我的pi和单个docker容器上的内存,都没有超出任何内存限制(具有top和docker状态)。
我已经删除了所有容器和图像,并从地面“ docker-compose up”。
Docker版本:
Client:
Version: 18.09.0
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:57:21 2018
OS/Arch: linux/arm
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:17:57 2018
OS/Arch: linux/arm
Experimental: false
Dockerfile
############################################################
# Dockerfile to build Flask App
# Based on
############################################################
# Set the base image
FROM debian:latest
# File Author / Maintainer
MAINTAINER Carlos Tighe
RUN apt-get update && apt-get install -y apache2 \
libapache2-mod-wsgi-py3 \
build-essential \
python3 \
python3-dev\
python3-pip \
vim \
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*
# Copy over and install the requirements
COPY ./app/requirements.txt /var/www/apache-flask/app/requirements.txt
RUN pip3 install -r /var/www/apache-flask/app/requirements.txt
# Copy over the apache configuration file and enable the site
COPY ./apache-flask.conf /etc/apache2/sites-available/apache-flask.conf
RUN a2ensite apache-flask
RUN a2enmod headers
# Copy over the wsgi file
COPY ./apache-flask.wsgi /var/www/apache-flask/apache-flask.wsgi
COPY ./run.py /var/www/apache-flask/run.py
COPY ./app /var/www/apache-flask/app/
RUN a2dissite 000-default.conf
RUN a2ensite apache-flask.conf
EXPOSE 80
WORKDIR /var/www/apache-flask
# CMD ["/bin/bash"]
CMD /usr/sbin/apache2ctl -D FOREGROUND
# The commands below get apache running but there are issues accessing it online
# The port is only available if you go to another port first
# ENTRYPOINT ["/sbin/init"]
# CMD ["/usr/sbin/apache2ctl"]
config.py
import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config(object):
SECRET_KEY = os.environ.get('SECRET_KEY') or 'configKEYgoesHERE'
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 #16MB
在浏览器中引发错误400的Python代码
@app.route('/addMacs', methods=['GET', 'POST'])
@login_required
def addMacs():
if not current_user.is_authenticated:
return redirect(url_for('index'))
if request.method == 'POST': # If POST, process request data
eprint("--------")
return str(request.form.get('data')) # <---- Throws error 400, specifically
eprint("---after Form0---")
# requestForm = request.form.to_dict() # Convert ImmutibleMultiDict (garbage) to normal Dict
# eprint("---form0---")
# data = list(requestForm.keys()) # Get list of keys from form (get user-ids to unregister)
# eprint("---form1---")
# if len(data) != 0: # If request had a form, this will be non-zero
# eprint("---form2---")
# macs, error = supp_extractMacsForm(requestForm["data"])
# eprint("---form3---")
# # eprint(str(requestForm["data"]))
# eprint(str(macs))
# return "Form Received"
eprint("---after Form---")
if 'file' not in request.files:
flash('No file uploaded.')
return render_template('addMacs.html', title='Add MACs')
file = request.files['file']
if file.filename == '':
flash('No file uploaded.')
return render_template('addMacs.html', title='Add MACs')
if file:
filename = secure_filename(file.filename)
return "File Received"
return render_template('addMacs.html', title='Add MACs')
我的文件和textarea发布请求的html代码。
<form action="" method="post">
<legend>Add MAC Addresses by text:</legend>
<textarea name="data" rows="7" cols="75" placeholder="Enter MAC Addresses here, separated by commas like so: AB:BA:CC:DD:EF:FE, AB:BA:CC:DD:EF:FF"></textarea>
<input type="submit">
</form>
<form action="" method="post" enctype="multipart/form-data">
<legend>Add MAC Addresses by file:</legend>
<input type="file" name="file"/>
<input type="submit">
</form>