hysds / pele

REST API for HySDS Datasets
Apache License 2.0
0 stars 0 forks source link

Login broken in Python3 #10

Open alexdunncs opened 3 years ago

alexdunncs commented 3 years ago

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

DustinKLo commented 3 years ago

looks like its related to PyJWT https://stackoverflow.com/a/65484529

according to the changelog, in v2.0.0+

Return tokens as string not bytes (#513) by @jpadilla

DustinKLo commented 3 years ago

we'll version lock it to PyJWT==1.7.1 for now and can properly address it later