Skip to content

fix: replace assertion error with proper method guessing when optional args precede URL#1879

Open
wahajahmed010 wants to merge 1 commit into
httpie:masterfrom
wahajahmed010:fix/1614-assertion-error-bearer-auth
Open

fix: replace assertion error with proper method guessing when optional args precede URL#1879
wahajahmed010 wants to merge 1 commit into
httpie:masterfrom
wahajahmed010:fix/1614-assertion-error-bearer-auth

Conversation

@wahajahmed010

Copy link
Copy Markdown

Description

When running httpie with optional arguments (e.g. --auth-type, --auth) between the HTTP method and URL, argparse can misparse the positional arguments, assigning the method to the URL slot and the URL to a request item. This previously caused an AssertionError in _guess_method().

Root Cause

argparse with nargs="?" for the optional method argument gets confused when optional arguments appear between positional arguments. The method ends up as None and the URL is parsed as a request item, triggering the bare assert not self.args.request_items.

Fix

Merged the two branches of _guess_method() so that when the method is None and request_items is non-empty, the same URL-as-method recovery logic is applied. This replaces the bare assert with graceful handling that correctly recovers the method and URL.

Testing

  • All 306 existing tests pass (3 pre-existing failures unrelated to this change)
  • Manual testing confirms the reported command now works:
    https POST --auth-type bearer --auth token123 https://example.org

Closes #1614


This PR was created with AI assistance (OpenClaw OSS Contributor pipeline).

…l args precede URL

When running httpie with optional arguments (e.g. --auth-type, --auth)
between the HTTP method and URL, argparse can misparse the positional
arguments, assigning the method to the URL slot and the URL to a
request item. This previously caused an AssertionError in
_guess_method().

The fix merges the two branches of _guess_method() so that when the
method is None and request_items is non-empty, the same URL-as-method
recovery logic is applied. This replaces the bare assert with graceful
handling.

Closes httpie#1614
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.

AssertionError when trying to POST with bearer auth

1 participant