Django 1.11.7 - Django Compressor - 参数5:<class'typeerror'=“”>:期望LP_OVERLAPPED实例而不是指向OVERLAPPED的指针

时间:2018-05-14 19:49:00

标签: django python-3.x django-compressor

我试图在我的Windows 10机器上启动并运行现有的Django 1.11.7(Python 3.5)项目。设置环境后,我现在在运行应用程序后看到主页,但是我访问的任何内部页面都出现以下错误:

argument 5: <class 'TypeError'>: expected LP_OVERLAPPED instance instead of pointer to OVERLAPPED

我已将此跟踪调用来自compress.py(Django压缩器)的一些压缩CSS文件调用,以及django.core内部的一些win32文件锁定代码,特别是这一行:https://github.com/django/django/blob/master/django/core/files/locks.py#L86(UnlockFileEx in下面的剪辑)。

class OVERLAPPED(Structure):
    _anonymous_ = ['_offset_union']
    _fields_ = [
        ('Internal', ULONG_PTR),
        ('InternalHigh', ULONG_PTR),
        ('_offset_union', _OFFSET_UNION),
        ('hEvent', HANDLE)]

LPOVERLAPPED = POINTER(OVERLAPPED)
....
def lock(f, flags):
    hfile = msvcrt.get_osfhandle(_fd(f))
    overlapped = OVERLAPPED()
    ret = LockFileEx(hfile, flags, 0, 0, 0xFFFF0000, byref(overlapped))
    return bool(ret)

def unlock(f):
    hfile = msvcrt.get_osfhandle(_fd(f))
    overlapped = OVERLAPPED()
    ret = UnlockFileEx(hfile, 0, 0, 0xFFFF0000, byref(overlapped))
    return bool(ret)

奇怪的是,在主页上调用LockFileEx和UnlockFileEx方法都没有错误。在成功和不成功的电话中检查当地人都没有任何结果。

堆栈跟踪,以防它有所帮助(更高的堆栈编辑):

  File "C:\x\env\lib\site-packages\compressor\templatetags\compress.py", line 127, in render
    return self.render_compressed(context, self.kind, self.mode, forced=forced)
  File "C:\x\env\lib\site-packages\compressor\templatetags\compress.py", line 103, in render_compressed
    rendered_output = compressor.output(mode, forced=forced)
  File "C:\x\env\lib\site-packages\compressor\css.py", line 49, in output
    ret.append(subnode.output(*args, **kwargs))
  File "C:\x\env\lib\site-packages\compressor\css.py", line 51, in output
    return super(CssCompressor, self).output(*args, **kwargs)
  File "C:\x\env\lib\site-packages\compressor\base.py", line 292, in output
    output = '\n'.join(self.filter_input(forced))
  File "C:\x\env\lib\site-packages\compressor\base.py", line 232, in filter_input
    for hunk in self.hunks(forced):
  File "C:\x\env\lib\site-packages\compressor\base.py", line 215, in hunks
    basename=basename)
  File "C:\x\env\lib\site-packages\compressor\base.py", line 307, in handle_output
    return output_func(mode, content, forced, basename)
  File "C:\x\env\lib\site-packages\compressor\base.py", line 319, in output_file
    self.storage.save(new_filepath, ContentFile(content.encode(self.charset)))
  File "C:\x\env\lib\site-packages\django\core\files\storage.py", line 54, in save
    return self._save(name, content)
  File "C:\x\env\lib\site-packages\django\core\files\storage.py", line 357, in _save
    locks.unlock(fd)
  File "C:\x\env\lib\site-packages\django\core\files\locks.py", line 86, in unlock
    ret = UnlockFileEx(hfile, 0, 0, 0xFFFF0000, byref(overlapped))

使用锁定/解锁的文件似乎是静态CSS文件。 JS和LESS都是抛出上述异常的人。看来该项目正在对CSS和JS过滤器使用yuglify,如果这有帮助的话。

1 个答案:

答案 0 :(得分:1)

在我的情况下,这是由于与youtube-dl包的冲突,其具有与django-compressor包类似命名的类,变量和方法。我能够通过“黑客攻击”两个实例中各种令牌的名称来确认这一点,导致错误argument 5: <class 'TypeError'>: expected LP_OVERLAPPED2 instance instead of pointer to OVERLAPPED3

我暂时从我的环境中删除了youtube-dl软件包,作为在本地开发环境中运行它的临时解决方案。