Giter Club home page Giter Club logo

django-backblazeb2-storage's People

Contributors

akeemmclennon avatar jshridha avatar metakermit avatar ogurtsov avatar royendgel avatar sonictherocketman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-backblazeb2-storage's Issues

Authorization token not issuing properly

Whenever I try to do an upload, I get the following error:
AttributeError at /admin/shop/difiles/add/
'BackBlazeB2' object has no attribute 'authorization_token'
Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/shop/difiles/add/

Django Version: 3.0.3
Python Version: 3.7.3
Installed Applications:
[...
'social_django',
'b2_storage',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 607, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1638, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1522, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1565, in _changeform_view
self.save_model(request, new_object, form, not add)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1081, in save_model
obj.save()
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/base.py", line 746, in save
force_update=force_update, update_fields=update_fields)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/base.py", line 784, in save_base
force_update, using, update_fields,
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/base.py", line 887, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/base.py", line 926, in _do_insert
using=using, raw=raw,
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/query.py", line 1204, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1383, in execute_sql
for sql, params in self.as_sql():
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1328, in as_sql
for obj in self.query.objs
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1328, in
for obj in self.query.objs
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1327, in
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1278, in pre_save_val
return field.pre_save(obj, add=True)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/fields/files.py", line 288, in pre_save
file.save(file.name, file.file, save=False)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/fields/files.py", line 86, in save
name = self.field.generate_filename(self.instance, name)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/db/models/fields/files.py", line 307, in generate_filename
return self.storage.generate_filename(filename)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/utils/functional.py", line 224, in inner
self._setup()
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/django/core/files/storage.py", line 364, in _setup
self._wrapped = get_storage_class()()
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/b2_storage/storage.py", line 22, in init
self.b2 = BackBlazeB2(**kwargs)
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/b2_storage/backblaze_b2.py", line 16, in init
self.get_bucket_id_by_name()
File "/home/nsh/Documents/Work/CGT/Code/shopcgt/venv/lib/python3.7/site-packages/b2_storage/backblaze_b2.py", line 86, in get_bucket_id_by_name
headers = {'Authorization': self.authorization_token}

Exception Type: AttributeError at /admin/shop/difiles/add/
Exception Value: 'BackBlazeB2' object has no attribute 'authorization_token'

Error when using a UTF8-encoded filename

Using a filename encoded as utf8 (i.e. a normal Python3 string) results in an error:

2017-03-21T21:49:40.383023+00:00 app[web.1]:   File "/app/apps/donations/views.py", line 29, in get_success_url
2017-03-21T21:49:40.383032+00:00 app[web.1]:     self.name = self.storage.save(name, content, max_length=self.field.max_length)
2017-03-21T21:49:40.383026+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/files.py", line 91, in save
2017-03-21T21:49:40.383034+00:00 app[web.1]:   File "/app/.heroku/src/django-backblazeb2-storage/b2_storage/backblaze_b2.py", line 59, in upload_file
2017-03-21T21:49:40.383035+00:00 app[web.1]:     download_response = requests.post(url, headers=headers, data=content.read())
2017-03-21T21:49:40.383036+00:00 app[web.1]:     return request('post', url, data=data, json=json, **kwargs)
2017-03-21T21:49:40.383033+00:00 app[web.1]:   File "/app/.heroku/src/django-backblazeb2-storage/b2_storage/storage.py", line 23, in save
2017-03-21T21:49:40.383037+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/requests/api.py", line 56, in request
2017-03-21T21:49:40.383033+00:00 app[web.1]:     resp = self.b2.upload_file(name, content)
2017-03-21T21:49:40.383037+00:00 app[web.1]:     return session.request(method=method, url=url, **kwargs)
2017-03-21T21:49:40.383035+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/requests/api.py", line 110, in post
2017-03-21T21:49:40.383038+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py", line 488, in request
2017-03-21T21:49:40.383039+00:00 app[web.1]:     resp = self.send(prep, **send_kwargs)
2017-03-21T21:49:40.383040+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/requests/adapters.py", line 423, in send
2017-03-21T21:49:40.383041+00:00 app[web.1]:     timeout=timeout
2017-03-21T21:49:40.383039+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py", line 609, in send
2017-03-21T21:49:40.383040+00:00 app[web.1]:     r = adapter.send(request, **kwargs)
2017-03-21T21:49:40.383042+00:00 app[web.1]:     chunked=chunked)
2017-03-21T21:49:40.383044+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 356, in _make_request
2017-03-21T21:49:40.383045+00:00 app[web.1]:     conn.request(method, url, **httplib_request_kw)
2017-03-21T21:49:40.383042+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
2017-03-21T21:49:40.383045+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/http/client.py", line 1239, in request
2017-03-21T21:49:40.383046+00:00 app[web.1]:     self._send_request(method, url, body, headers, encode_chunked)
2017-03-21T21:49:40.383048+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/http/client.py", line 1212, in putheader
2017-03-21T21:49:40.383049+00:00 app[web.1]:     values[i] = one_value.encode('latin-1')
2017-03-21T21:49:40.383047+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/http/client.py", line 1280, in _send_request
2017-03-21T21:49:40.383047+00:00 app[web.1]:     self.putheader(hdr, value)
2017-03-21T21:49:40.383053+00:00 app[web.1]: UnicodeEncodeError: 'latin-1' codec can't encode character '\u0107' in position 30: ordinal not in range(256)

This is how I'm using the storage (works when I use an ASCII string):

from io import BytesIO
...
self.barcode.save(
    "Maja Majić",
    BytesIO(response.content),
    save=True
)

False statement in the docs about INSTALLED_APPS

if you are making alot of api calls I recommend you to use the b2_storage.authorise,
it stores the seconds in your database and reuses the authorisation_token for other calls.
for this you need to include 'b2_storage.authorise', in your INSTALLED_APPS

There's no such thing as b2_storage.authorise in the code, so adding it to INSTALLED_APPS causes an Exception. Was it planned but not implemented? Was it implemented differently but not updated in the docs?

Error on upload after installing

Getting this error upon installing the package and trying to upload a file.

Traceback (most recent call last): File "/root/virtual/nimbus/local/lib/python2.7/site-packages/newrelic-2.40.0.34/newrelic/hooks/framework_django.py", line 497, in wrapper return wrapped(*args, **kwargs) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/views/generic/base.py", line 69, in view return self.dispatch(request, *args, **kwargs) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/newrelic-2.40.0.34/newrelic/hooks/component_djangorestframework.py", line 27, in _nr_wrapper_APIView_dispatch_ return wrapped(*args, **kwargs) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 57, in wrapped_view return view_func(*args, **kwargs) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/rest_framework/views.py", line 400, in dispatch response = self.handle_exception(exc) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/rest_framework/views.py", line 397, in dispatch response = handler(request, *args, **kwargs) File "/root/virtual/nimbus/Nimbus/nimbus/apps/api/views.py", line 57, in post media_item.save() File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/base.py", line 545, in save force_update=force_update, update_fields=update_fields) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/base.py", line 573, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/base.py", line 654, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/base.py", line 687, in _do_insert using=using, raw=raw) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/manager.py", line 232, in _insert return insert_query(self.model, objs, fields, **kwargs) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/query.py", line 1511, in insert_query return query.get_compiler(using=using).execute_sql(return_id) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 897, in execute_sql for sql, params in self.as_sql(): File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 855, in as_sql for obj in self.query.objs File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/fields/files.py", line 252, in pre_save file.save(file.name, file, save=False) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/db/models/fields/files.py", line 86, in save self.name = self.storage.save(name, content) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/utils/functional.py", line 213, in inner self._setup() File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/core/files/storage.py", line 286, in _setup self._wrapped = get_storage_class()() File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/core/files/storage.py", line 282, in get_storage_class return import_by_path(import_path or settings.DEFAULT_FILE_STORAGE) File "/root/virtual/nimbus/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 31, in import_by_path error_prefix, module_path, class_name)) ImproperlyConfigured: Module "b2_storage" does not define a "B2Storage" attribute/class

Errors on Python 3.6

Seems like some imports should be updated for Python 3.6…

/app/.heroku/python/lib/python3.6/site-packages/b2_storage/storage.py in <module>()
      1 from tempfile import TemporaryFile
      2
----> 3 import StringIO
      4 from django.conf import settings
      5 from django.core.files.storage import Storage

ModuleNotFoundError: No module named 'StringIO'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.