You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_api_encode encodes bool/datetime list elements raw (e.g. flags[0]=True instead of true) #1956
stripe._encode._api_encode converts bool and datetime values to the forms the API expects at the top level and inside nested dicts (bool → "true"/"false", datetime → unix timestamp), but yields them raw when they are direct elements of a list.
The request body/query string is built with urlencode(list(_api_encode(params))) (in _api_requestor.py), so a list parameter containing a boolean is serialized as "True"/"False" (Python str(bool)) and a list containing a datetime is serialized as its str() repr instead of a unix timestamp. Multipart form encoding is affected too, since MultipartDataGenerator.add_params also goes through _api_encode.
N/A — client-side request encoding, independent of API version
Additional context
Root cause
In _api_encode (stripe/_encode.py), the list branch handles dict/_data elements and nested list/tuple elements, but every other element — including bool and datetime.datetime — falls through to else: yield (encoded_key, sv) raw. The top-level code has explicit datetime and bool branches; the list branch does not.
(Nested dict values are unaffected because they recurse back through _api_encode; nested lists are unaffected because they go through _encode_nested_dict + recursion. Only direct scalar elements of a list are affected.)
The list branch of _api_encode yields scalar elements as-is, so the bool and datetime conversions that apply at the top level and inside nested dicts are skipped for direct list elements ({"flags": [True, False]} is sent as flags[0]=True&flags[1]=False).
Opening pull requests here is limited to collaborators, so the fix is on a branch instead, in case it is useful: pcbeingused333/stripe-python@master...c0486-encode-list-scalars. It adds the two missing conversions in the list branch, two tests in tests/test_encode.py that fail without the change, and a .hark changefile.
This change was prepared with the help of an AI coding assistant (Claude Code).
Thanks @ramya-stripe, and thank you for opening this up to community contributions! I've opened #1978 with the fix, regression tests, and a changefile.
Activity
pcbeingused333 commentedon Nov 2, 2026
The list branch of
_api_encodeyields scalar elements as-is, so theboolanddatetimeconversions that apply at the top level and inside nested dicts are skipped for direct list elements ({"flags": [True, False]}is sent asflags[0]=True&flags[1]=False).Opening pull requests here is limited to collaborators, so the fix is on a branch instead, in case it is useful: pcbeingused333/stripe-python@master...c0486-encode-list-scalars. It adds the two missing conversions in the list branch, two tests in
tests/test_encode.pythat fail without the change, and a.harkchangefile.This change was prepared with the help of an AI coding assistant (Claude Code).
ramya-stripe commentedon Nov 10, 2026
Thank you for reporting @alphasafal and @pcbeingused333
We will try and fix this by the end of the year
alphasafal commentedon Nov 11, 2026
Thanks @ramya-stripe. The branch linked in the issue has the fix with regression tests if it saves you time; feel free to take it as is.
ramya-stripe commentedon Nov 12, 2026
Hey @alphasafal
We just temporarily opened up community contributions. So if you want to send a PR, please do!
alphasafal commentedon Nov 12, 2026
Thanks @ramya-stripe, and thank you for opening this up to community contributions! I've opened #1978 with the fix, regression tests, and a changefile.