如何更正binascii.Error:不正确的填充?

时间:2019-08-17 11:48:38

标签: django python-3.x

我正在view.py中写一个视图,我试图获取已经从Header登录的用户名(b2b_pan)。 然后我发现可以使用request.META来获得它, 但是我遇到了一些问题,我不知道为什么

以下是代码:

class InventoryListView(generics.ListAPIView):
    permission_classes=[IsAuthenticated,]

    pan = ""
    b2b_pan  = ""

    # def header_auth_view(request):


    def get (self,request, *args, **kwargs):
        the_serializer = InventorySerializer(data = request.data)

        auth_header = request.META['HTTP_AUTHORIZATION']
        encoded_credentials = auth_header.split(' ')[1]
     #remove basic to isolate credentials (basic username:password)
        decoded_credentials = base64.b64decode(encoded_credentials).decode("utf-8").split(':')
        b2b_pan = decoded_credentials[0]

        if the_serializer.is_valid():

            pan = request.data['pan']

错误是:

  

b64decode中的文件“ /home/.venv/lib/python3.7/base64.py”,第87行       返回binascii.a2b_base64(s)   binascii.Error:填充不正确

0 个答案:

没有答案