Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubelshooting raise TypeError("quote_from_bytes() expected bytes")

Tags:

python

rest

web

I have an error raised by the following piece of code

    def __to_canonical_querystring_post(self, params):
    canonical_querystring = ""
    # parameters have to be sorted alphabetically for the signing part
    for param_key, param_value in sorted(params.items()):
        if canonical_querystring != "":
            canonical_querystring += "&"
        canonical_querystring += param_key + "=" + urllib.parse.quote(param_value)
    return canonical_querystring

The params are Make_Payment_params = { "debitAccountNumber": 12003189487, "creditAccountNumber": 12065812627, "amount": 100, "requestedExecutionDate": "2019-03-09" }

and the error is raise TypeError("quote_from_bytes() expected bytes") TypeError: quote_from_bytes() expected bytes

Help is much appreciated

like image 281
jameson Avatar asked Mar 09 '19 15:03

jameson


1 Answers

The argument to urllib.parse.quote must be a string, but your code sometimes passes integers instead. Changing the call to something like urllib.parse.quote(str(param_value)) should fix the problem.

like image 103
Tadeusz Sznuk Avatar answered Nov 18 '22 23:11

Tadeusz Sznuk