2
我使用Django 1.9和Python 3.我已經安裝python-memcached
,當我嘗試cache.set("foo", "bar")
我得到這個錯誤:爲什麼會這樣Django的cache.set()類型的錯誤
TypeError: a bytes-like object is required, not 'str'
任何想法?我確保設置中間件並添加緩存到settings.py
我使用Django 1.9和Python 3.我已經安裝python-memcached
,當我嘗試cache.set("foo", "bar")
我得到這個錯誤:爲什麼會這樣Django的cache.set()類型的錯誤
TypeError: a bytes-like object is required, not 'str'
任何想法?我確保設置中間件並添加緩存到settings.py
錯誤來自Python 3中的字符串/ unicode更改。在Python 2中,字符串類型是字節,但在Python 3中,字符串類型與字節類型是分開的 - 這是造成你看到的錯誤。
如果您將Python 3.x與memcached一起使用,請使用python3-memcached
包。這是替代python-memcached
的下降。
pip install python3-memcached