Open jamesdreid opened 4 years ago
Thanks for detailed bug report and more investigation around this.
Are you saying that your use case worked in py2 but failed in py3, you know where to fix and it confirmed to be working? If I understand it correctly, can you please create a PR with the fix?
I apologize for the ambiguity, but I have not tested the URLEncoded webhook functions in Python2 so my comment above about the original code working in Python2 was an assumption.
As far as the change to line 404 of the router.py file in my install is suggested above, it did correct the issue, I am no longer seeing the error and the webhook is processing as expected, but I am not sure what the impact will be in other systems aside from my own.
As far as the PR is concerned, I will see if I can work that out, but it may take some time as I am not a programmer by trade and I am still familiarizing myself with Git and how it functions.
Your way of debugging and communicating this issue is technically solid! Thanks again for more details @jamesdreid and for reporting this bug.
Hi @jamesdreid , This issue seems to be a good initiation of my journey towards contribution to FOSS projects. Can you please assign this to me?
SUMMARY
Provide a quick summary of your bug report.
STACKSTORM VERSION
Paste the output of
st2 --version
:st2 3.1.0, on Python 3.6.8
OS, environment, install method
Post what OS you are running this on, along with any other relevant information/
Ubuntu 18.04.3 LTS - Manual install
Steps to reproduce the problem
When running the system with Python3, configuring a webhook as a trigger to receive data from a remote source. Configure the remote source to send text data that is URL encoded in the body of the message, as shown in sample curl output below:
curl --location --request POST 'https://127.0.0.1/api/v1/webhooks/test_hook' \ --header 'St2-Api-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-raw 'MyVariableOne=ValueOne&MyVariableTwo=ValueTwo'
Expected Results
What did you expect to happen when running the steps above?
The system should properly process the URL encoded body data and should return it a proper JSON
{ "MyVariableOne": [ "ValueOne" ], "MyVariableTwo": [ "ValueTwo\n" ] }
Actual Results
What happened? What output did you get?
The process fails with the following debug output:
I believe I have isolated the issue and it is due to the encoding for the body data that is returned by the WSGI server. In Python2, the body data was returned as a string so line 404 (below) in the router.py file worked properly to process the URL encoded body data.
data = urlparse.parse_qs(req.body)
In Python3, the WSGI server encoded the body data as a byte string and it needed to be decoded as a string before being processed further. Changing line 404 to the following, corrected the error and processed the web hook data properly:
data = urlparse.parse_qs(req.body.decode('utf-8'))
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!