Skip to content

Conversation

@zzstoatzz
Copy link
Contributor

@zzstoatzz zzstoatzz commented Jul 12, 2025

closes #613

Fixes httpx deprecation warning when making requests with the atproto client.

The warning was:

DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content.

Changes

  • Modified _handle_kwargs() in base.py to use content parameter instead of data when passing JSON content to httpx
  • Fixed typo in function name: _handle_kwagrs_handle_kwargs

Technical Details

Recent versions of httpx (0.27.x) have escalated the deprecation warning for using data= with bytes/text content. The warning was made more visible in PR #3319 (merged October 28, 2024) by adding stacklevel=2 to the warning.

Since we serialize our models to JSON strings before passing to httpx, we need to use the content parameter. The httpx API distinguishes between:

  • content= for raw bytes/text content (what we need for JSON strings)
  • data= for dictionary data that will be form-encoded

when we detect JSON content type and have data to send, we:

  1. Move the JSON string from kwargs['data'] to kwargs['content']
  2. Remove the data key to avoid conflicts

@zzstoatzz zzstoatzz force-pushed the fix-613 branch 2 times, most recently from fbc29e1 to e095719 Compare July 14, 2025 14:10
@MarshalX
Copy link
Owner

MarshalX commented Jul 22, 2025

does it compatible with old httpx versions? should we bump min required version of httpx? should we pick param name depending on httpx version in runtime?

- Replace 'data' with 'content' when passing bytes/text to httpx
- Fix typo: _handle_kwagrs -> _handle_kwargs
- Addresses deprecation warning: 'Use content=<...> to upload raw bytes/text content'

Fixes MarshalX#613
@zzstoatzz
Copy link
Contributor Author

does it compatible with old httpx versions? should we bump min required version of httpx? should we pick param name depending on httpx version in runtime?

@MarshalX I don't think we need to bump because

  • atproto requires httpx >=0.25.0
  • The content= parameter we're using has been in httpx since at least 0.18.0

so as is, this should work with all supported versions

@MarshalX MarshalX merged commit 7ed3650 into MarshalX:main Oct 11, 2025
23 checks passed
@MarshalX
Copy link
Owner

Awesome, thank you!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecation warning from httpx: Use 'content=<...>'

2 participants