Q: Flask's request.args return different data between Python2 and Python3 I'm using Flask for a web app. And I find that the request.args returns different data when I convert the URL parameters to a dict.
Code is below.
How to make Flask under Python3 return the same data as it returns under Python2?
from flask import Flask,request
import numpy as np
import json

app = Flask(__name__)

@app.route('/')
def hello():
    request.parameter_storage_class = dict
    return json.dumps(dict(request.args))

app.run()



*

*Python2: {"abc": ["hello"]}

*Python3: {"abc": "hello"}

A: This looks like it's due to differences in how MultiDicts are converted to dicts between python 2 and 3, which is surprising since you're setting parameter_storage_class.
If you want consistent behaviour across Python 2 and 3, you can leave the parameter_storage_class as the default MultiDict and use one of the following instead of dict(request.args):
def hello():
    return request.args.to_dict()  # == {"abc": "hello"}
    # or:
    return request.args.to_dict(flat=False)  # == {"abc": ["hello"]}

