CodexBloom - Programming Q&A Platform

Flask app running into 'ValueError: too many values to unpack' when trying to access multiple query parameters

๐Ÿ‘€ Views: 69 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-08
Flask Python Web Development

I've hit a wall trying to I'm wondering if anyone has experience with I've been banging my head against this for hours... I'm currently developing a Flask application where I'm trying to access multiple query parameters from a request URL. However, I'm working with a `ValueError: too many values to unpack (expected 2)` when I attempt to unpack the parameters in my view function. The function is supposed to accept two query parameters: `item` and `category`. Hereโ€™s the code snippet of my route: ```python from flask import Flask, request app = Flask(__name__) @app.route('/filter', methods=['GET']) def filter_items(): item, category = request.args.get('item'), request.args.get('category') return f'Item: {item}, Category: {category}' if __name__ == '__main__': app.run(debug=True) ``` When I visit the URL `http://localhost:5000/filter?item=book&category=fiction`, I expect to see `Item: book, Category: fiction`. However, I'm getting the above-mentioned behavior. Iโ€™ve verified that the query parameters are being passed correctly, and Iโ€™ve also tried accessing them individually like this: ```python item = request.args.get('item') category = request.args.get('category') ``` But that did not resolve the scenario. Additionally, Iโ€™ve checked to ensure that there are no conflicting routes or request methods. Could someone guide to understand why I'm getting this behavior and how to properly unpack the query parameters? My development environment is Ubuntu. Any help would be greatly appreciated! This is my first time working with Python 3.9. The project is a desktop app built with Python. What's the correct way to implement this?