8000 example in tutorial on URL 'https://webpy.org/cookbook/sessions' is not working. · Issue #644 · webpy/webpy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

example in tutorial on URL 'https://webpy.org/cookbook/sessions' is not working. #644

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

Closed
abhijitnarvekar opened this issue May 22, 2020 · 3 comments · Fixed by #645
Closed

Comments

@abhijitnarvekar
Copy link

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

@lujoamel4
Copy link
lujoamel4 commented Jun 4, 2020

The same on MySql. I had

create table sessions (
    session_id char(128) UNIQUE NOT NULL,
    atime timestamp NOT NULL default current_timestamp,
    data text
);

so I ran:

ALTER TABLE sessions DROP COLUMN data;
ALTER TABLE sessions ADD COLUMN data VARBINARY(255);

and then it's works for me.

@iredmail
Copy link
Contributor
iredmail commented Jun 5, 2020

Could you help verify this patch? It works for me.
#645

@abhijitnarvekar
Copy link
Author
abhijitnarvekar commented Jun 10, 2020 via email

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

Successfully merging a pull request may close this issue.

3 participants
0