Fix double encoding of string parameters#263
Fix double encoding of string parameters#263GriceTurrble merged 1 commit intopython-amazon-mws:masterpython-amazon-mws/python-amazon-mws:masterfrom adamantike:fix-double-encodingCopy head branch name to clipboard
Conversation
Currently, the `0.8.x` branch breaks string parameters by encoding them twice, first in the `clean_params_dict` function, and then in `calc_request_description`. Because of this, parameters prone to have characters that must be escaped, like `NextToken` and URLs, do not work correctly. #258 was an attempt to fix this issue, but only for timestamp fields. Strings are still broken. This solution is a backport of a commit (#65) that is already present in the `develop` branch, where the `calc_request_description` function is no longer responsible for escaping the received parameters. It also rollbacks #258, as `clean_date` must encode the received values now.
|
Gentle heads up to @GriceTurrble, who reviewed the mentioned PRs. |
|
@adamantike do you have an example of a call that failed before this fix - so I can do a live test to check ? |
|
@Bobspadger, sure! A simple example is trying to get the second page of a import datetime
import mws
next_token = None
last_updated_after = datetime.datetime(2020, 1, 1)
orders_api = mws.Orders(
access_key="...",
secret_key="...",
account_id="...",
auth_token="...",
region="US",
)
for _ in range(2):
response = orders_api.list_orders(
marketplaceids=("ATVPDKIKX0DER",),
lastupdatedafter=last_updated_after,
max_results=1,
next_token=next_token,
)
next_token = response.parsed["NextToken"]
assert next_tokenFor the second call, with version <ErrorResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
<Error>
<Type>Sender</Type>
<Code>NextTokenCorrupted</Code>
<Message>We could not decode your NextToken. Possible reasons include: a transmission error, improper quoting or a truncation problem.</Message>
</Error>
<RequestId>...</RequestId>
</ErrorResponse> |
|
My apologies for the delay on my end. Home life and such. Not ignoring this, I promise! |
|
@GriceTurrble, no worries! Just to confirm, we have forked |
|
@Bobspadger @GriceTurrble, gentle ping on this one! |
|
I also just hit this corner of the internet while working for my employer. @adamantike is the mentioned fork actually publicly available? |
|
@ihucos, I haven't made it publicly available, as I would prefer for this fix to quickly be merged, and avoid more people from start depending on a fork. It's literally just this PR applied on top of |
|
@adamantike thanks for the message. We decided to wait for a fix upstream. I could to something to work towards it if it makes sense. |
|
Hi Sorry, I've not forgotten about this but work has got quite hectic so not had the time to really look into this. I am hoping to in the next week or so and try to look at what is truly happening, as this is only a new issue since there were some items back-ported from the develop branch. I'd like to not be in a situation where we keep releasing point updates for essentially the same bug, |
|
@GriceTurrble, if there are no planned changes in the short term, do you mind tagging and releasing a new patch version, to have this fix available for current 0.8.x users? :) |
|
Thanks for the new release, @GriceTurrble! cc @ihucos, this change is now available in version |
|
|
|
First time for me to actually perform the PyPI release, so that was a learning process. However, 0.8.14 is now available on PyPI: https://pypi.org/project/mws/0.8.14/ |
Currently, the
0.8.xbranch breaks string parameters by encoding them twice, first in theclean_params_dictfunction, and then incalc_request_description. Because of this, parameters prone to have characters that must be escaped, likeNextTokenand URLs, do not work correctly.#258 was an attempt to fix this issue, but only for timestamp fields. Strings are still broken.
This solution is a backport of a commit (#65) that is already present in the
developbranch, where thecalc_request_descriptionfunction is no longer responsible for escaping the received parameters.It also rollbacks #258, as
clean_datemust encode the received values now.