1

I am trying to make a Django API for handling lightning payments, and I need to implement some functionalities such as unlocking wallet, changing password etc. I am getting "Incorrect padding" and I don't know how to fix it. This is my view.py:

from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from rest_framework.parsers import JSONParser
import os
import base64, codecs, json, requests

class ChangePassword(APIView):
    def post(self, request):
        url = "https://localhost:8080/v1/changepassword"
        cert_path = "/Users/user1/Library/Application Support/Lnd/tls.cert"
        data = {
            "current_password": base64.b64decode(
                request.data["current_password"]
            ).decode("utf-8"),
            "new_password": base64.b64decode(request.data["new_password"]).decode(
                "utf-8"
            ),
        }
        r = requests.post(url, verify=cert_path, data=json.dumps(data))
        if r.status_code == 200:
            data = r.json()
            return Response(data, status=status.HTTP_200_OK)
        return Response({"error": "Request failed"}, status=r.status_code)

I am using the LND Rest documentation https://api.lightning.community/#v1-changepassword.

Thanks in advance for your help :)

1 Answer 1

0

The solution is to change the way we encoded/decoding by:

...

data = {
            "wallet_password": base64.b64encode(
                bytes(request.data["wallet_password"], "UTF-8")
            ).decode(),

...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.