[GH-ISSUE #172] Basic auth on Python 3 #160

Closed
opened 2026-02-26 09:36:12 +03:00 by kerem · 3 comments
Owner

Originally created by @jhass on GitHub (Sep 29, 2014).
Original GitHub issue: https://github.com/nsupdate-info/nsupdate.info/issues/172

Originally assigned to: @ThomasWaldmann on GitHub.

Getting the following exception here:


  File "/usr/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File "/usr/lib/python3.4/site-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)

  File "/usr/lib/python3.4/site-packages/django/views/generic/base.py", line 87, in dispatch
    return handler(request, *args, **kwargs)

  File "./nsupdate/utils/log.py", line 124, in caller
    return func(*args, **kwargs)

  File "./nsupdate/api/views.py", line 197, in get
    username, password = basic_authenticate(auth)

  File "./nsupdate/api/views.py", line 118, in basic_authenticate
    auth = auth.decode('utf-8')

AttributeError: 'str' object has no attribute 'decode'


<WSGIRequest
path:/nic/update,
GET:<QueryDict: {'myip': ['...'], 'hostname': ['...']}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'CONTENT_LENGTH': '',
 'CONTENT_TYPE': '',
 'CSRF_COOKIE': 'XEnCpp62oHEiPEs0fwaWgCIZziTaQumB',
 'DOCUMENT_ROOT': '/etc/nginx/html',
 'HTTP_ACCEPT': '*/*',
 'HTTP_AUTHORIZATION': 'Basic .....',
 'HTTP_HOST': '....',
 'HTTP_USER_AGENT': 'curl/7.29.0',
 'HTTP_X_FORWARDED_PROTO': 'https',
 'PATH_INFO': '/nic/update',
 'QUERY_STRING': '...',
 'REMOTE_ADDR': '...',
 'REMOTE_PORT': '57008',
 'REQUEST_METHOD': 'GET',
 'REQUEST_URI': '/nic/update?hostname=...&myip=....',
 'SCRIPT_NAME': '',
 'SERVER_NAME': '...',
 'SERVER_PORT': '443',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'uwsgi.core': 1,
 'uwsgi.version': b'2.0.7',
 'wsgi.errors': <_io.TextIOWrapper name=2 mode='w' encoding='UTF-8'>,
 'wsgi.file_wrapper': <built-in function uwsgi_sendfile>,
 'wsgi.input': <uwsgi._Input object at 0xb5281920>,
 'wsgi.multiprocess': False,
 'wsgi.multithread': True,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}>

Just removing the offending line seems to work here, not sure how well it would play on other setups.

Originally created by @jhass on GitHub (Sep 29, 2014). Original GitHub issue: https://github.com/nsupdate-info/nsupdate.info/issues/172 Originally assigned to: @ThomasWaldmann on GitHub. Getting the following exception here: ``` File "/usr/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python3.4/site-packages/django/views/generic/base.py", line 69, in view return self.dispatch(request, *args, **kwargs) File "/usr/lib/python3.4/site-packages/django/views/generic/base.py", line 87, in dispatch return handler(request, *args, **kwargs) File "./nsupdate/utils/log.py", line 124, in caller return func(*args, **kwargs) File "./nsupdate/api/views.py", line 197, in get username, password = basic_authenticate(auth) File "./nsupdate/api/views.py", line 118, in basic_authenticate auth = auth.decode('utf-8') AttributeError: 'str' object has no attribute 'decode' <WSGIRequest path:/nic/update, GET:<QueryDict: {'myip': ['...'], 'hostname': ['...']}>, POST:<QueryDict: {}>, COOKIES:{}, META:{'CONTENT_LENGTH': '', 'CONTENT_TYPE': '', 'CSRF_COOKIE': 'XEnCpp62oHEiPEs0fwaWgCIZziTaQumB', 'DOCUMENT_ROOT': '/etc/nginx/html', 'HTTP_ACCEPT': '*/*', 'HTTP_AUTHORIZATION': 'Basic .....', 'HTTP_HOST': '....', 'HTTP_USER_AGENT': 'curl/7.29.0', 'HTTP_X_FORWARDED_PROTO': 'https', 'PATH_INFO': '/nic/update', 'QUERY_STRING': '...', 'REMOTE_ADDR': '...', 'REMOTE_PORT': '57008', 'REQUEST_METHOD': 'GET', 'REQUEST_URI': '/nic/update?hostname=...&myip=....', 'SCRIPT_NAME': '', 'SERVER_NAME': '...', 'SERVER_PORT': '443', 'SERVER_PROTOCOL': 'HTTP/1.1', 'uwsgi.core': 1, 'uwsgi.version': b'2.0.7', 'wsgi.errors': <_io.TextIOWrapper name=2 mode='w' encoding='UTF-8'>, 'wsgi.file_wrapper': <built-in function uwsgi_sendfile>, 'wsgi.input': <uwsgi._Input object at 0xb5281920>, 'wsgi.multiprocess': False, 'wsgi.multithread': True, 'wsgi.run_once': False, 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0)}> ``` Just removing the offending line seems to work here, not sure how well it would play on other setups.
kerem closed this issue 2026-02-26 09:36:12 +03:00
Author
Owner

@ThomasWaldmann commented on GitHub (Sep 29, 2014):

seems like the tests were a bit backwards as they gave a bytes object as auth, thus the decode() worked for the tests, but not in reality on python3...

I changed tests a little so they generate same auth object type as the web server and added some asserts and docs.

Can you please test in practice on a python3-based nsupdate.info deployment?

BTW, it would be great if somebody would continuously run a py3 based install in practice (I run it on 2.7).

<!-- gh-comment-id:57149619 --> @ThomasWaldmann commented on GitHub (Sep 29, 2014): seems like the tests were a bit backwards as they gave a bytes object as auth, thus the decode() worked for the tests, but not in reality on python3... I changed tests a little so they generate same auth object type as the web server and added some asserts and docs. Can you please test in practice on a python3-based nsupdate.info deployment? BTW, it would be great if somebody would continuously run a py3 based install in practice (I run it on 2.7).
Author
Owner

@ThomasWaldmann commented on GitHub (Sep 29, 2014):

fixed by 8d50874e3a

<!-- gh-comment-id:57149668 --> @ThomasWaldmann commented on GitHub (Sep 29, 2014): fixed by 8d50874e3a4e243833548c421e0bc1756b72b03c
Author
Owner

@jhass commented on GitHub (Sep 29, 2014):

I think I'll run one for a while though only for myself, so probably not hitting all functionality all the time, though I should be able to report such bugs in core functionality ;)

<!-- gh-comment-id:57161567 --> @jhass commented on GitHub (Sep 29, 2014): I think I'll run one for a while though only for myself, so probably not hitting all functionality all the time, though I should be able to report such bugs in core functionality ;)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nsupdate.info-nsupdate-info#160
No description provided.