Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

python - The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS

I got an error: "The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS".

Error says that TooManyFieldsSent at /api/upload.

I wrote in my views.py.

def upload(request):
    id, array = common(request)

    if request.FILES:
        file = request.FILES['req'].temporary_file_path()
    else:
        return HttpResponse('<h1>NG</h1>')

    return HttpResponse('<h1>OK</h1>')

def common(request):
    id = json_body.get("access", "0")
    if id == "":
        id = "0"

    s = []
    with open(ID_TXT, 'r') as f:
        for line in f:
            s += list(map(int, line.rstrip().split(',')[:-1]))

    array = [s[i:i + 2] for i in range(0, len(s), 2)]

    return id, array

I post access & req data by using POSTMAN like: enter image description here

I think this error is limitation of being able to send file size, so I added the code to settings.py

DATA_UPLOAD_MAX_MEMORY_SIZE = 100000000

But the error didn't solved. I read this page: How to avoid "The number of GET/POST parameters exceeded" error? as a reference. How should I fix this?

question from:https://stackoverflow.com/questions/47585583/the-number-of-get-post-parameters-exceeded-settings-data-upload-max-number-field

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

as django's doc says, the value of DATA_UPLOAD_MAX_NUMBER_FIELDS is default 1000, so once your form contains more fields than that number you will get the TooManyFields error.

check out here: https://docs.djangoproject.com/en/1.11/ref/settings/

so the solution is simple I think, if DATA_UPLOAD_MAX_NUMBER_FIELDS exists if your settings.py, change it's value to a higher one, or, if it doesn't, add it to settings.py:

DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240 # higher than the count of fields

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...