Invalid input of type: 'CacheKey'. Convert to a byte, string or number first.
See original GitHub issueDjango run with the latest version of the redis module crashes:
Invalid input of type: 'CacheKey'. Convert to a byte, string or number first.
It’s this message. Full stack trace:
Environment:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 2.1.3
Python Version: 3.6.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.postgres',
'django.contrib.sites',
'django.contrib.flatpages',
'django.contrib.sitemaps',
'django.contrib.admin',
'django.contrib.admindocs',
'rest_framework',
'rest_framework_docs',
'rest_framework.authtoken',
'drf_yasg',
'django_bleach',
'cspreports',
'captcha',
'django_markdown2',
'crispy_forms',
'api2',
'headers',
'worker',
'cookies',
'sslyze.apps.CoreConfig',
'flash',
'rss',
'seo',
'news',
'contact',
'browser_extension',
'adstxt',
'vuln',
'busint',
'csp_analytics',
'reporting_api',
'register_site.apps.CoreConfig',
'utils',
'stats',
'phantomjs',
'malware',
'paypal.standard.ipn',
'payments.apps.PaymentsConfig')
Installed Middleware:
['django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'middleware.dnt.DoNotTrackMiddleware',
'middleware.preload.ResourceHintsMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware']
Traceback:
File "/home/kravietz/wps2/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/kravietz/wps2/lib/python3.6/site-packages/django/utils/deprecation.py" in __call__
90. response = self.process_request(request)
File "/home/kravietz/wps2/lib/python3.6/site-packages/django/middleware/cache.py" in process_request
137. cache_key = get_cache_key(request, self.key_prefix, 'GET', cache=self.cache)
File "/home/kravietz/wps2/lib/python3.6/site-packages/django/utils/cache.py" in get_cache_key
335. headerlist = cache.get(cache_key)
File "/home/kravietz/wps2/lib/python3.6/site-packages/django_redis/cache.py" in _decorator
32. return method(self, *args, **kwargs)
File "/home/kravietz/wps2/lib/python3.6/site-packages/django_redis/cache.py" in get
81. client=client)
File "/home/kravietz/wps2/lib/python3.6/site-packages/django_redis/client/default.py" in get
202. value = client.get(key)
File "/home/kravietz/wps2/lib/python3.6/site-packages/redis/client.py" in get
1207. return self.execute_command('GET', name)
File "/home/kravietz/wps2/lib/python3.6/site-packages/redis/client.py" in execute_command
754. connection.send_command(*args)
File "/home/kravietz/wps2/lib/python3.6/site-packages/redis/connection.py" in send_command
619. self.send_packed_command(self.pack_command(*args))
File "/home/kravietz/wps2/lib/python3.6/site-packages/redis/connection.py" in pack_command
659. for arg in imap(self.encoder.encode, args):
File "/home/kravietz/wps2/lib/python3.6/site-packages/redis/connection.py" in encode
124. "byte, string or number first." % typename)
Exception Type: DataError at /
Exception Value: Invalid input of type: 'CacheKey'. Convert to a byte, string or number first.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Invalid input of type: 'CacheKey'. Convert to a byte, string or ...
Django run with the latest version of the redis module crashes: Invalid input of type: 'CacheKey'. Convert to a byte, string or number...
Read more >Django compress error: Invalid input of type: 'CacheKey'
Convert to a byte, string or number first. It doesn't seem to be an issue in one of the static files but a...
Read more >Convert to a byte, string or number first. (#1129) · Issues
Convert to a byte, string or number first. ... Redis doesn't cast to string anymore. ... DataError: Invalid input of type: 'CacheKey'.
Read more >'CacheKey'. Convert to a bytes, string, int or float first.
Invalid input of type : 'CacheKey'. Convert to a bytes, string, int or float first. 原因redis版本过高解决方案pip install redis==2.10.6. 复制链接.
Read more >Invalid input of type: 'CacheKey'. Convert to a byte, string or ...
DataError : Invalid input of type: 'CacheKey'. Convert to a byte, string or number first. 将python原生redis包降级为2.1.0即可,或者不使用django.core.cache.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Related django-redis issue: https://github.com/niwinz/django-redis/issues/342
django-redis isn’t constraining it’s dependency on py-redis to version 2.
https://github.com/niwinz/django-redis/blob/master/setup.py#L25
I imagine a lot of people are going to get stung by this so expect django-redis to get fixed soon. If you can’t wait for the fix, you could pin the last v2 of py-redis in your requirements.txt file
redis==2.10.6redis-py 3.0 only accepts keys and values as bytes, strings or numbers. This is a backwards incompatible change listed in the release notes.
I suspect django-redis needs to be updated to convert the
CacheKeytype into a string before sending it into redis-py.