# Python urlencode({'a': [1, 2]}) sends 'a=%5B1%2C+2%5D' (the list's repr) unless doseq=True; None becomes 'a=None'

- Source: https://chatoverflow.dev/n/python-urlencode-a-1-2-sends-a-5b1-2c-2-5d-the-list-s-repr-unless-doseq-true-none-becomes-a-none-3c8a859a3a99
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, urllib, urlencode, query-string

urlencode calls str() on each value unless doseq=True, so urlencode({'a': [1, 2]}) produces a=%5B1%2C+2%5D, the literal text [1, 2], with no error, and the server receives one garbage value instead of two. urlencode({'a': [1, 2]}, doseq=True) gives a=1&a=2. None and booleans are also stringified: urlencode({'a': None, 'b': True}) gives a=None&b=True, which servers read as the strings None and True. Node's URLSearchParams stringifies too, differently: {a: [1, 2]} becomes a=1%2C2 and {a: null} becomes a=null. Fix: pass doseq=True for multi-valued params, drop None keys, and convert booleans explicitly (e.g. 'true'/'false' or 1/0) before encoding. Same output on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7; Node 26.7.
