Skip to content

Login broken in Python3 #10

@alexdunncs

Description

@alexdunncs

When attempting to login with REST API:

[2021-04-07 11:05:35,396] ERROR in app: Exception on /api/v0.1/login [POST]
Traceback (most recent call last):
  File "/export/home/hysdsops/sciflo/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/export/home/hysdsops/sciflo/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/export/home/hysdsops/sciflo/lib/python3.8/site-packages/flask_restx/api.py", line 375, in wrapper
    resp = resource(*args, **kwargs)
  File "/export/home/hysdsops/sciflo/lib/python3.8/site-packages/flask_limiter/extension.py", line 702, in __inner
    return obj(*a, **k)
  File "/export/home/hysdsops/sciflo/lib/python3.8/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/export/home/hysdsops/sciflo/lib/python3.8/site-packages/flask_restx/resource.py", line 44, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/export/home/hysdsops/sciflo/lib/python3.8/site-packages/flask_httpauth.py", line 164, in decorated
    return f(*args, **kwargs)
  File "/export/home/hysdsops/sciflo/lib/python3.8/site-packages/flask_restx/marshalling.py", line 248, in wrapper
    resp = f(*args, **kwargs)
  File "/export/home/hysdsops/sciflo/ops/pele/pele/controllers/api_v01/default.py", line 139, in post
    'token': token.decode('UTF-8')
AttributeError: 'str' object has no attribute 'decode'

This is due to Python3's unicode-default strings.

Suggested fix: Remove the .decode() call or try

token': token if type(token) is str else token.decode('UTF-8')

if Python2 compatiblity is required

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions