StackStorm / StackStorm/st2

st2 POST API with content type= "application/x-www-form-urlencoded" not working

Open
#5,512 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #5513 by @sravs-dev — closed without merging
bug
Dominant language
Python
Stars
6.5k
Forks
787
PR merge metrics
No merged PRs in 30d

Description

SUMMARY

Provide a quick summary of your bug report.

STACKSTORM VERSION

3.5

OS, environment, install method

Post what OS you are running this on, along with any other relevant information/

Running on Mac OS, installed using Docker. Issue is related to the rest api handling, nothing to do with host environment.

Steps to reproduce the problem

Make a post api to /sso/callback with a payload body of type "application/x-www-form-urlencoded"

Expected Results

What did you expect to happen when running the steps above?
st2 api should be able to parse the payload body into string and process it

Actual Results

What happened? What output did you get?

API failed to load bytes input in the body to a dictionary, hence returned 500 with the following stacktrace.
Fix needed: Bytes input should be converted to string before processing.

2021-12-20 18:04:00,275 139680124778496 DEBUG router [-] Missing x-api-model definition for st2auth.controllers.v1.sso:idp_callback_controller.post, using generic Body model. 2021-12-20 18:04:00,275 139680124778496 ERROR error_handling [-] API call failed: __init__() keywords must be strings Traceback (most recent call last): File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/middleware/error_handling.py", line 49, in __call__ return self.app(environ, start_response) File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/router.py", line 735, in as_wsgi resp = self(req) File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/router.py", line 560, in __call__ instance = self._get_model_instance(model_cls=model, data=data) File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/router.py", line 750, in _get_model_instance raise e File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/router.py", line 740, in _get_model_instance instance = model_cls(**data) TypeError: __init__() keywords must be strings (_exception_class='TypeError',_exception_message='__init__() keywords must be strings',_exception_data={}) 2021-12-20 18:04:00,275 139680124778496 DEBUG router [-] Match path: /sso/callback 2021-12-20 18:04:00,276 139680124778496 INFO logging [-] 548d58ec-1be5-4d43-8d51-a9926b21a6af - 500 39 3.427ms (method='POST',path='/sso/callback',remote_addr='172.21.0.1',status=500,runtime=3.427,content_length=39,request_id='548d58ec-1be5-4d43-8d51-a9926b21a6af')

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in st2common/router.py at _get_model_instance, the entry point named in the traceback, and reproduce the POST to /sso/callback with an application/x-www-form-urlencoded body. Done means the body bytes are handled as strings, the request is processed successfully, and the endpoint no longer returns a 500 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.