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

Python 'Unknown flags on get' error while querying memcached #144

Open
OuterCloud opened this issue Jun 20, 2018 · 0 comments
Open

Python 'Unknown flags on get' error while querying memcached #144

OuterCloud opened this issue Jun 20, 2018 · 0 comments

Comments

@OuterCloud
Copy link

I have solved this problem.

This is the solution in Chinese: https://www.cnblogs.com/LanTianYou/p/9204431.html

The solution is to modify the final else-block content in the method "_recv_value" in the python file "memcache.py".

The _recv_value method should be like this:

def _recv_value(self, server, flags, rlen):
    rlen += 2  # include \r\n
    buf = server.recv(rlen)
    if len(buf) != rlen:
        raise _Error("received %d bytes when expecting %d"
                     % (len(buf), rlen))

    if len(buf) == rlen:
        buf = buf[:-2]  # strip \r\n

    if flags & Client._FLAG_COMPRESSED:
        buf = self.decompressor(buf)
        flags &= ~Client._FLAG_COMPRESSED
    if flags == 0:
        # Bare bytes
        val = buf
    elif flags & Client._FLAG_TEXT:
        val = buf.decode('utf-8')
    elif flags & Client._FLAG_INTEGER:
        val = int(buf)
    elif flags & Client._FLAG_LONG:
        if six.PY3:
            val = int(buf)
        else:
            val = long(buf)  # noqa: F821
    elif flags & Client._FLAG_PICKLE:
        try:
            file = BytesIO(buf)
            unpickler = self.unpickler(file)
            if self.persistent_load:
                unpickler.persistent_load = self.persistent_load
            val = unpickler.load()
        except Exception as e:
            self.debuglog('Pickle error: %s\n' % e)
            return None
    else:
        self.debuglog("unknown flags on get: %x\n" % flags)
        # 注释掉这行
        # raise ValueError('Unknown flags on get: %x' % flags)
        # 设定返回值
        val = buf

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

No branches or pull requests

1 participant