Uploaded image for project: 'Couchbase Python Client Library'
  1. Couchbase Python Client Library
  2. PYCBC-560

Fix travel-sample to work on Python 3.7

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.2.0
    • None
    • None
    • 1

    Description

      From: https://forums.couchbase.com/t/travel-sample-web-app-can-not-login-create-user/19766/5

      This currently fails because JWT.encode returns a byte sequence (UTF8 encoded), which jsonify does not accept for encoding:

       

      Connecting to: couchbase://localhost/travel-sample?username=Administrator * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit) 127.0.0.1 - - [15/Jan/2019 19:12:59] "GET / HTTP/1.1" 302 - 127.0.0.1 - - [15/Jan/2019 19:12:59] "GET /static/index.html HTTP/1.1" 200 - 127.0.0.1 - - [15/Jan/2019 19:13:00] "GET /static/assets/CBTravel.LOGO.png HTTP/1.1" 200 - 127.0.0.1 - - [15/Jan/2019 19:13:00] "GET /static/assets/poweredBy.01.png HTTP/1.1" 200 - [2019-01-15 19:13:06,733] ERROR in app: Exception on /api/user/signup [POST] Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_classy.py", line 200, in proxy response = view(**request.view_args) File "travel.py", line 183, in signup respjson = jsonify({'data': {'token': token}}) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/json.py", line 263, in jsonify (dumps(data, indent=indent, separators=separators), '\n'), File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/json.py", line 123, in dumps rv = _json.dumps(obj, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 238, in dumps **kw).encode(obj) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 201, in encode chunks = list(chunks) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 431, in _iterencode yield from _iterencode_dict(o, _current_indent_level) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict yield from chunks File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict yield from chunks File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 438, in _iterencode o = _default(o) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/json.py", line 80, in default return _json.JSONEncoder.default(self, o) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type bytes is not JSON serializable 127.0.0.1 - - [15/Jan/2019 19:13:06] "POST /api/user/signup HTTP/1.1" 500 -
      

      This works in Python 2 because `str` and `bytes` are aliases, but in Python 3 they are not.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          Ellis.Breen Ellis Breen added a comment - - edited

          Daniel Roberts has finished this for Python3.7 as per https://github.com/Danzibob/try-cb-python/commits/6.5. Also works at least partially for SDK3, though there are some possibly SDK-related issues to resolve still.

          Ellis.Breen Ellis Breen added a comment - - edited Daniel Roberts has finished this for Python3.7 as per https://github.com/Danzibob/try-cb-python/commits/6.5 . Also works at least partially for SDK3, though there are some possibly SDK-related issues to resolve still.
          jared.casey Jared Casey added a comment -

          The latest travel sample utilizes Docker. Should help users get up and running much faster.

          jared.casey Jared Casey added a comment - The latest travel sample utilizes Docker . Should help users get up and running much faster.

          People

            jared.casey Jared Casey
            Ellis.Breen Ellis Breen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty