Skip to content

Boolean query parameters are sent as True/False, which the X API rejects with 400 (e.g. stream.update_rules(dry_run=False)) #8

Open

Description

@simonszalai

Summary

Generated clients put Python bool values straight into the params dict passed to requests. requests serializes them with str(), so the query string carries dry_run=False / dry_run=True. The X API only accepts lowercase true / false and answers HTTP 400.

Reproduction

Seen in production with xdk 0.9.0. The code is unchanged in 0.10.6 (latest). Python 3.13, requests 2.33.

from xdk import Client

client = Client(bearer_token="...")
client.stream.update_rules(
    body={"add": [{"value": "from:XDevelopers", "tag": "repro"}]},
    dry_run=False,
)

Request URL:

POST https://api.x.com/2/tweets/search/stream/rules?dry_run=False

Response:

400 Bad Request
'False' is not a valid boolean, must be true or false

dry_run=True is encoded the same way (dry_run=True), so it should fail too. Leaving the argument out works.

The encoding is easy to see without calling the API:

import requests
requests.Request("POST", "https://api.x.com/2/tweets/search/stream/rules",
                 params={"dry_run": False}).prepare().url
# 'https://api.x.com/2/tweets/search/stream/rules?dry_run=False'

Cause

xdk/stream/client.py, StreamClient.update_rules (0.10.6):

params = {}
if dry_run is not None:
    params["dry_run"] = dry_run
if delete_all is not None:
    params["delete_all"] = delete_all
...
response = self.client.session.post(url, params=params, headers=headers, json=json_data)

Nothing converts the bool to the API's true / false.

Affected parameters in 0.10.6

Every Optional[bool] query parameter of a generated client:

  • stream.update_rules: dry_run, delete_all
  • broadcasts (xdk/broadcasts/client.py, line 508): roll_forward

Suggested fix

Lowercase booleans when the generator builds query params, for example:

if dry_run is not None:
    params["dry_run"] = str(dry_run).lower()

or one helper in the shared request path that maps bool values in params to "true" / "false". Since this code is generated, the fix probably belongs in the generator template (xdevplatform/xdk).

Workaround

Omit boolean query arguments entirely. The API then uses its defaults (for update_rules, the change is applied).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions