Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: encoding without a string argument #121

Open
niketnishi opened this issue Nov 17, 2020 · 5 comments
Open

TypeError: encoding without a string argument #121

niketnishi opened this issue Nov 17, 2020 · 5 comments
Assignees

Comments

@niketnishi
Copy link

payload_body = request.body
webhook_signature = request.headers['X-Razorpay-Signature']
client = razorpay.Client(auth=(RAZORPAY_KEY, RAZORPAY_PASS))
client.utility.verify_webhook_signature(payload_body, webhook_signature, secret_key)

The above was working fine with python 2.7 but gives an error with python 3.6.12.
As the documentation specifies "Do not parse or cast the webhook request body.:
While generating signature at your end, ensure that the webhook body passed as an argument is the raw webhook request body. Do not parse or cast the webhook request body."

And this gives a TypeError: encoding without a string argument. And when I typecast payload_body to string using str() this throws an exception saying that razorpay.errors.SignatureVerificationError: Razorpay Signature Verification Failed which means the generated sha256 does not match the webhook signature I receive from your end.

Please help to resolve the issue.

@MamtaBhagia
Copy link

MamtaBhagia commented Dec 23, 2020

@niketnishi
You can resolve your issue in two ways -
body = str(request.body, 'utf-8'). # This will decode the bytes into string
OR
body = json.dumps(request.data, separators=(',', ':'))
https://stackoverflow.com/questions/53706973/razorpay-webhook-signature-verification-error

@RazorpayTeam - It seems like we are converting the request.body from bytes to string, and then in your code you are just converting it back to bytes. Please remove the double conversion - seems unnecessary.

@niketnishi
Copy link
Author

@niketnishi
You can resolve your issue in two ways -
body = str(request.body, 'utf-8'). # This will decode the bytes into string
OR
body = json.dumps(request.data, separators=(',', ':'))
https://stackoverflow.com/questions/53706973/razorpay-webhook-signature-verification-error

@RazorpayTeam - It seems like we are converting the request.body from bytes to string, and then in your code you are just converting it back to bytes. Please remove the double conversion - seems unnecessary.

The first solution gives an error
Razorpay Signature Verification Failed

And the 2nd solution gives an error
Object of type 'bytes' is not JSON serializable

namantam1 added a commit to namantam1/razorpay-python that referenced this issue Jul 19, 2021
namantam1 added a commit to namantam1/razorpay-python that referenced this issue Jul 23, 2021
namantam1 added a commit to namantam1/razorpay-python that referenced this issue Oct 1, 2021
@ankitdas13
Copy link
Contributor

Hi @niketnishi sorry for the delay. We do not receive any reports of this kind of issue from our users at present. Could you please confirm us is it resolved or not ?

@niketnishi
Copy link
Author

niketnishi commented Nov 28, 2022 via email

@ankitdas13
Copy link
Contributor

@niketnishi could you please close this issue? If the issue still persists you can re open this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants