Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A signature can't be generated with a url with a query param with no value #20

Open
mikaylathompson opened this issue Sep 26, 2024 · 0 comments

Comments

@mikaylathompson
Copy link

We're using requests-auth-aws-sigv4 to sign requests for an Opensearch cluster. One common syntax for the api is to add ?v to the end of a url to get a verbose response. This seems to break when sigv4 signing the request.

INFO:console_link.models.cluster:Performing request: GET https://cluster-endpoint.com:443/_cat/indices/_all?v
DEBUG:requests_auth_aws_sigv4:Starting authentication with amzdate=20240924T032547Z
DEBUG:requests_auth_aws_sigv4:Request URL: ParseResult(scheme='https', netloc='cluster-endpoint.com:443', path='/_cat/indices/_all', params='', query='v', fragment='')
Traceback (most recent call last):
...
  File "/root/lib/console_link/console_link/middleware/clusters.py", line 27, in cat_indices
    r = cluster.call_api(cat_indices_path)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/lib/console_link/console_link/models/cluster.py", line 155, in call_api
    r = session.request(
        ^^^^^^^^^^^^^^^^
  File "/.venv/lib64/python3.11/site-packages/requests/sessions.py", line 575, in request
    prep = self.prepare_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib64/python3.11/site-packages/requests/sessions.py", line 484, in prepare_request
    p.prepare(
  File "/.venv/lib64/python3.11/site-packages/requests/models.py", line 371, in prepare
    self.prepare_auth(auth, url)
  File "/.venv/lib64/python3.11/site-packages/requests/models.py", line 602, in prepare_auth
    r = auth(self)
        ^^^^^^^^^^
  File "/.venv/lib64/python3.11/site-packages/requests_auth_aws_sigv4/__init__.py", line 114, in __call__
    qs = dict(map(lambda i: i.split('='), p.query.split('&')))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: dictionary update sequence element #0 has length 1; 2 is required

The signature succeeds if the query parameter is formatted with a value, e.g. https://cluster-endpoint.com:443/_cat/indices/_all?v=true

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

No branches or pull requests

1 participant