1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# reference: https://github.com/Pylons/webob/issues/431


         else:
             # if no active cart in session, create one.
             cart = Cart()

             # The issue appeared when attempting to port from Python 2 to 3.

             # When the serializer is JSON instead of pickle I get the following:
             # TypeError: Unicode-objects must be encoded before hashing
             #request.session["active_cart_id"] = str(cart.id)

             # Still using the JSON serializer when I encode to
             # to utf-8 in order to work with bytes, I get this error:
             # TypeError: Object of type bytes is not JSON serializable
             #request.session["active_cart_id"] = str(cart.id).encode("utf-8")

             # this appears to work fine with pickle.
             request.session["active_cart_id"] = str(cart.id)

             # note for reviewer: cart.id is of type uuid object.

             request.dbsession.add(cart)
             request.dbsession.flush()


2021-07-01 11:08:32,657 ERROR [waitress:404][waitress-0] Exception while serving /
Traceback (most recent call last):
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/waitress/channel.py", line 397, in service
    task.service()
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/waitress/task.py", line 168, in service
    self.execute()
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/waitress/task.py", line 434, in execute
    app_iter = self.channel.server.application(environ, start_response)
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/pyramid/router.py", line 270, in __call__
    response = self.execution_policy(environ, self)
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/pyramid_retry/__init__.py", line 127, in retry_policy
    response = router.invoke_request(request)
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/pyramid/router.py", line 248, in invoke_request
    request._process_response_callbacks(response)
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/pyramid/request.py", line 85, in _process_response_callbacks
    callback(self, response)
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/pyramid/session.py", line 258, in set_cookie_callback
    self._set_cookie(response)
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/pyramid/session.py", line 325, in _set_cookie
    serializer.dumps((self.accessed, self.created, dict(self)))
  File "/home/fox/git/make_post_sell/env/lib64/python3.9/site-packages/webob/cookies.py", line 660, in dumps
    sig = hmac.new(self.salted_secret, cstruct, self.digestmod).digest()
  File "/usr/lib64/python3.9/hmac.py", line 170, in new
    return HMAC(key, msg, digestmod)
  File "/usr/lib64/python3.9/hmac.py", line 93, in __init__
    self.update(msg)
  File "/usr/lib64/python3.9/hmac.py", line 113, in update
    self._inner.update(msg)
TypeError: Unicode-objects must be encoded before hashing