example in tutorial on URL 'https://webpy.org/cookbook/sessions' is not working.
Hi,
Refering to tutorial on URL https://webpy.org/cookbook/sessions
the sample code is alright except that if implemented in a Postgres DB, the data-type of the data column must be bytea instead of text. Otherwise, the following error is reported during run-time.
File "/usr/lib/python3.6/base64.py", line 510, in _input_type_check
m = memoryview(s)
TypeError: memoryview: a bytes-like object is required, not 'str'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/abhijit/.local/lib/python3.6/site-packages/web/application.py", line 288, in process
return p(lambda: process(processors))
File "/home/abhijit/.local/lib/python3.6/site-packages/web/session.py", line 102, in _processor
self._load()
File "/home/abhijit/.local/lib/python3.6/site-packages/web/session.py", line 120, in _load
d = self.store[self.session_id]
File "/home/abhijit/.local/lib/python3.6/site-packages/web/session.py", line 348, in __getitem__
return self.decode(s.data)
File "/home/abhijit/.local/lib/python3.6/site-packages/web/session.py", line 246, in decode
pickled = decodebytes(session_data)
File "/usr/lib/python3.6/base64.py", line 545, in decodebytes
_input_type_check(s)
File "/usr/lib/python3.6/base64.py", line 513, in _input_type_check
raise TypeError(msg) from err
TypeError: expected bytes-like object, not str
127.0.0.1:54780 - - [22/May/2020 17:58:54] "HTTP/1.1 GET /count" - 500 Internal Server Error
In the interest of beginners(such as me) in the community, please update the document with the correct database table specification(likely as follows). I found it working without issues on Python3.6 with Postgresql 12.
create table sessions ( session_id char(128) primary key, atime timestamp default now(), data bytea) ;
Thanks,
Abhijit