Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 Client Error: Unauthorized for url #10

Open
idealatom opened this issue Apr 23, 2020 · 6 comments
Open

401 Client Error: Unauthorized for url #10

idealatom opened this issue Apr 23, 2020 · 6 comments

Comments

@idealatom
Copy link
Contributor

Hi. I'm using your storage as a default file storage. I'm reading file content in some celery tasks and everything works ok, but after some moment I'm starting to get HTTP 401 Error. After restarting celery the error disappears but on the next day it's come back.
It's looks like your Auth class for some reason doesn't reauthenticate after token expired. It's weird because the container is public and file content can be accessed without authentication.

Stacktrace (most recent call last):

  File "mail/tasks.py", line 46, in send_email
    content = attachment.file.read()
  File "django/core/files/utils.py", line 16, in <lambda>
    read = property(lambda self: self.file.read)
  File "django/db/models/fields/files.py", line 43, in _get_file
    self._file = self.storage.open(self.name, 'rb')
  File "queued_storage/backends.py", line 172, in open
    return self.get_storage(name).open(name, mode)
  File "django/core/files/storage.py", line 36, in open
    return self._open(name, mode)
  File "django_selectel_storage/storage.py", line 13, in _open
    return base.ContentFile(self.container.open(name).read())
  File "django_selectel_storage/selectel.py", line 110, in open
    stream=True).raw
  File "django_selectel_storage/selectel.py", line 106, in perform_request
    **kwargs)
  File "django_selectel_storage/selectel.py", line 79, in perform_request
    resp.raise_for_status()
  File "requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)

401 Client Error: Unauthorized for url: https://144411.selcdn.ru/3dplitka_media/uploads/organizations/requisites/Hafizova.docx

I'm using Python 3.7.6 with Django 2.2.12 and django-selectel-storage 1.0.0

@marazmiki
Copy link
Owner

Suppose, you're right in your point about it could not refresh the token. Gonna research it deeply.

It's weird because the container is public and file content can be accessed without authentication.

I think it's because the token is wrong. If you provide the correct one or just drop it off, it would work as expected. At least, I clicked on the link from the traceback and got a .docx file

@idealatom
Copy link
Contributor Author

Thanks for a fast reply. Looking forward for a fix, now I'm just catching 401 exceptions and reauthenticate your storage manually but it's a dirty way.

@marazmiki
Copy link
Owner

Well, if it works, who cares? :)

BTW... Maybe if you have some time for that, can you please fork the app and put some loggers there to get what's happening there? What data is sent, timestamps, etc.

After all, you have a working stand reproducing an error :) Not sure if I can repeat it fast.

@idealatom
Copy link
Contributor Author

Well, if it works, who cares? :)

My inner perfectionist :) I'll try to investigate this problem deeper in the next days and send you a pull request with fix

@marazmiki
Copy link
Owner

marazmiki commented Apr 23, 2020 via email

idealatom added a commit to idealatom/django-selectel-storage that referenced this issue Apr 28, 2020
@idealatom
Copy link
Contributor Author

After some debugging I didn't found any reason why I'm getting those 401 errors. So I just added a check to reauthenticate and repeat request if needed.

marazmiki added a commit that referenced this issue May 4, 2020
reauthenticate on unexpected 401 errors, fix of #10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants