故障排除引发TypeError(“ quote_from_bytes()预期字节”)

jam*_*son 0 python rest web

以下代码段引发了错误

    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
Run Code Online (Sandbox Code Playgroud)

参数为Make_Payment_params = {“ debitAccountNumber”:12003189487,“ creditAccountNumber”:12065812627,“ amount”:100,“ requestedExecutionDate”:“ 2019-03-09”}

并引发错误TypeError(“ quote_from_bytes()预期字节”)TypeError:quote_from_bytes()预期字节

非常感谢帮助

小智 5

参数to urllib.parse.quote必须是字符串,但是您的代码有时会传递整数。将呼叫更改为类似内容urllib.parse.quote(str(param_value))应该可以解决该问题。