Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 填充不正确。使用谷歌浏览器的Django_Python 3.x_Django_Google Chrome - Fatal编程技术网

Python 3.x 填充不正确。使用谷歌浏览器的Django

Python 3.x 填充不正确。使用谷歌浏览器的Django,python-3.x,django,google-chrome,Python 3.x,Django,Google Chrome,请跳过第一部分,查找更新部分。。。 我昨天问了这个问题,但删除了它,因为我似乎提供的信息太少,并且解释得很糟糕。但这是一种解决方案,但解决方案涉及不同的问题。我只是针对这个特殊的问题实施了一些想法,我想和大家分享一下,这样可能会对其他人有所帮助 因此,我遇到的问题是:我的网站基于Django应用程序,当我使用谷歌Chrome时,它将其解释为(据我所知)32位,同时它是64位(我不确定我在这里对问题的描述是否正确,但总的想法是),谷歌Chrome失败并给出以下消息: 填充不正确 我为解决这个问题所

请跳过第一部分,查找更新部分。。。 我昨天问了这个问题,但删除了它,因为我似乎提供的信息太少,并且解释得很糟糕。但这是一种解决方案,但解决方案涉及不同的问题。我只是针对这个特殊的问题实施了一些想法,我想和大家分享一下,这样可能会对其他人有所帮助

因此,我遇到的问题是:我的网站基于Django应用程序,当我使用谷歌Chrome时,它将其解释为(据我所知)32位,同时它是64位(我不确定我在这里对问题的描述是否正确,但总的想法是),谷歌Chrome失败并给出以下消息:

填充不正确

我为解决这个问题所做的一切。解决方案基于:

所以我进入了:/usr/local/lib/python3.8/base64.py 函数名为b64decode,位于第87行。它看起来像:

def b64decode(s, altchars=None, validate=False):
    """Decode the Base64 encoded bytes-like object or ASCII string s.

    Optional altchars must be a bytes-like object or ASCII string of length 2
    which specifies the alternative alphabet used instead of the '+' and '/'
    characters.

    The result is returned as a bytes object.  A binascii.Error is raised if
    s is incorrectly padded.

    If validate is False (the default), characters that are neither in the
    normal base-64 alphabet nor the alternative alphabet are discarded prior
    to the padding check.  If validate is True, these non-alphabet characters
    in the input result in a binascii.Error.
    """
    s = _bytes_from_decode_data(s)
    if altchars is not None:
        altchars = _bytes_from_decode_data(altchars)
        assert len(altchars) == 2, repr(altchars)
        s = s.translate(bytes.maketrans(altchars, b'+/'))
        if validate and not re.fullmatch(b'[A-Za-z0-9+/]*={0,2}', s):
        raise binascii.Error('Non-base64 digit found')
    return binascii.a2b_base64(s)
为了解决此问题,我更改了以下行: 返回binascii.a2b_base64(s) 为此: 返回binascii.a2b_base64(s+b'================================================')已更正

这可能是太多的“=”,但他们会去任何方式。。。但这些等号允许谷歌浏览器正确定义base64

这个错误只发生在谷歌浏览器上

更新 上述方法不知何故并不真正有效。。。它适用于一台使用一个键的计算机,并使用不同的环境键断开另一台计算机。所以结果本身是不好的。 因此,在视图文件中,我有以下代码:

def index(request):
        now = datetime.datetime.now()
        num_visits=request.session.get('num_visits', 0)
        request.session['num_visits']=num_visits+1
        context = {
                'now':now,
                num_visits':num_visits,
        }
        return render(request, 'index.html', context=context)
因此,只要我关闭为用户会话计数而设计的以下代码部分,一切都会变得正常,我没有问题: num\u visions=request.session.get('num\u visions',0) 请求.会话['num_访问量']=num_访问量+1 访问次数:访问次数

所以,我猜这些线是“不正确填充”错误的根源。。。但我对他们做了什么错事是被发现的。。。任何帮助都很好