Error while uploading with django-audiofield - django

Hey i am trying to use django-field but came across this error:
Traceback (most recent call last):
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\contrib\admin\options.py", line 575, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\utils\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\contrib\admin\sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\contrib\admin\options.py", line 1557, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\utils\decorators.py", line 62, in _wrapper
return bound_func(*args, **kwargs)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\utils\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\utils\decorators.py", line 58, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\contrib\admin\options.py", line 1451, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\contrib\admin\options.py", line 1491, in _changeform_view
self.save_model(request, new_object, form, not add)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\contrib\admin\options.py", line 1027, in save_model
obj.save()
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\db\models\base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\db\models\base.py", line 769, in save_base
update_fields=update_fields, raw=raw, using=using,
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\dispatch\dispatcher.py", line 178, in send
for receiver in self._live_receivers(sender)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\django\dispatch\dispatcher.py", line 178, in <listcomp>
for receiver in self._live_receivers(sender)
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\audiofield\fields.py", line 223, in _rename_audio
self._convert_audio(dst_fullpath, instance, ext[1:4])
File "C:\Users\Sebastian\Envs\blog\lib\site-packages\audiofield\fields.py", line 140, in _convert_audio
response = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "C:\Python36\Lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Python36\Lib\subprocess.py", line 992, in _execute_child
startupinfo)
[WinError 2] FileNotFoundError
The audiofile is actually saved in media directory in the root of the project as specified in settings.py
Don't know where to look for. Have not been able to find a similar topic and the way to solve this...

Related

openEdx server error on exchange_access_token with azuread-oauth2

I'm now working on deploying openEdx system and encounter an error while logging in via Azure AD from the mobile device.
The web Azure AD login is working fine and I can also get access_token from azure ad.
But, when I try to exchange azure token with openEdx token via /oauth2/exchange_access_token/azuread-oauth2/ url, I'm getting the following error due to the empty response.
AttributeError: 'NoneType' object has no attribute 'get'
Hence I'm fairly new to the openEdx, I have a hard time figuring out to fix the issue. Please help to direct me into the right path to fixing this issue. Following is the detail error log.
Thanks in advance
Apr 1 12:38:45 edxapp [service_variant=lms][django.request][env:sandbox] ERROR [edxapp 24509] [exception.py:135] - Internal Server Error: /oauth2/exchange_access_token/azuread-oauth2/
Traceback (most recent call last):
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner
return func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/oauth_dispatch/views.py", line 57, in dispatch
return view(request, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/social_django/utils.py", line 49, in wrapper
return func(request, backend, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/auth_exchange/views.py", line 44, in dispatch
return super(AccessTokenExchangeBase, self).dispatch(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py", line 489, in dispatch
response = self.handle_exception(exc)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py", line 449, in handle_exception
self.raise_uncaught_exception(exc)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py", line 486, in dispatch
response = handler(request, *args, **kwargs)
File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/auth_exchange/views.py", line 57, in post
if not form.is_valid():
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/forms/forms.py", line 183, in is_valid
return self.is_bound and not self.errors
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/forms/forms.py", line 175, in errors
self.full_clean()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/forms/forms.py", line 385, in full_clean
self._clean_form()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/provider/forms.py", line 63, in _clean_form
super(OAuthForm, self)._clean_form()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/forms/forms.py", line 412, in _clean_form
cleaned_data = self.clean()
File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/auth_exchange/forms.py", line 95, in clean
user = backend.do_auth(access_token, allow_inactive_user=True)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/social_core/utils.py", line 252, in wrapper
return func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/social_core/backends/oauth.py", line 410, in do_auth
data = self.user_data(access_token, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/social_core/backends/azuread.py", line 80, in user_data
id_token = response.get('id_token')
AttributeError: 'NoneType' object has no attribute 'get'
social-core is throwing the error because the response is NoneType. It makes sense that social-core is responsible here as you are aiming for 3rd party oAuth2.
If it works on web, then the None response is explainable only if the configuration is wrong.
Now, steps to troubleshoot:
Check edx.properties to ensure that the config directory is properly set.
Check your config and local yamls to ensure that oauth config is proper. [instead of simply configuring ios.yaml]
Make sure you followed additional instructions provided here.
If nothing else works, check the config for social-auth as stated here.
Hope that helps! Cheers!

AttributeError: 'NoneType' object has no attribute 'get' at openEdx exchange_token api

I was working on the azure ad login for openEdx mobile app and as mentioned in the title, I got the NoneType response at token_exchange endpoint from azure ad.
Azure login have no problem authentication the user from the website login but login from the mobile got 'Service unavailable response' due to the following error log on the server.
I suspect the configuration issue but as far as I checked, i only need to set 'SOCIAL_AUTH_OAUTH_SECRETS' from lms.auth.json and 'THIRD_PARTY_AUTH_BACKENDS' and 'ENABLE_THIRD_PARTY_AUTH' from lms.env.json.
Please let me know if I miss something out. Thanks in advance
Apr 1 12:38:45 edxapp [service_variant=lms][django.request][env:sandbox] ERROR [edxapp 24509] [exception.py:135] - Internal Server Error: /oauth2/exchange_access_token/azuread-oauth2/
Traceback (most recent call last):
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner
return func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/oauth_dispatch/views.py", line 57, in dispatch
return view(request, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/social_django/utils.py", line 49, in wrapper
return func(request, backend, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/auth_exchange/views.py", line 44, in dispatch
return super(AccessTokenExchangeBase, self).dispatch(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py", line 489, in dispatch
response = self.handle_exception(exc)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py", line 449, in handle_exception
self.raise_uncaught_exception(exc)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py", line 486, in dispatch
response = handler(request, *args, **kwargs)
File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/auth_exchange/views.py", line 57, in post
if not form.is_valid():
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/forms/forms.py", line 183, in is_valid
return self.is_bound and not self.errors
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/forms/forms.py", line 175, in errors
self.full_clean()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/forms/forms.py", line 385, in full_clean
self._clean_form()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/provider/forms.py", line 63, in _clean_form
super(OAuthForm, self)._clean_form()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/forms/forms.py", line 412, in _clean_form
cleaned_data = self.clean()
File "/edx/app/edxapp/edx-platform/openedx/core/djangoapps/auth_exchange/forms.py", line 95, in clean
user = backend.do_auth(access_token, allow_inactive_user=True)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/social_core/utils.py", line 252, in wrapper
return func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/social_core/backends/oauth.py", line 410, in do_auth
data = self.user_data(access_token, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/social_core/backends/azuread.py", line 80, in user_data
id_token = response.get('id_token')
AttributeError: 'NoneType' object has no attribute 'get'

Django ViewFlow: Navigate Step based on Validation

I am using the HelloWorld example located at the ViewFlow cookbook.
The whole source code is same as the helloworld project with the only change being:
flows.py
check_approve = (
flow.If(lambda activation: activation.process.approved)
.Then(this.send)
.Else(this.start) # Edited (was this.end)
)
So basically I intend that if user keeps the Approved checkbox as un-selected and proceeds then it will push the task back to the start step.
I get this error when I run it:
NotImplementedError at /workflow/helloworld/helloworld/3/approve/11/
No exception message supplied
Internal Server Error: /workflow/helloworld/helloworld/3/approve/11/
Traceback (most recent call last):
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/usr/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/decorators.py", line 213, in _wrapper
return view(request, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/flow/views/task.py", line 70, in dispatch
return super(BaseFlowMixin, self).dispatch(request, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/views/generic/edit.py", line 240, in post
return super(BaseUpdateView, self).post(request, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/views/generic/edit.py", line 183, in post
return self.form_valid(form)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/flow/views/task.py", line 86, in form_valid
self.activation_done(*args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/flow/views/task.py", line 78, in activation_done
self.activation.done()
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 44, in __call__
return self.descriptor(self.instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 112, in __call__
result = self.func(instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 384, in done
self.activate_next()
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 44, in __call__
return self.descriptor(self.instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 112, in __call__
result = self.func(instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 396, in activate_next
self.flow_task._next.activate(prev_activation=self, token=self.task.token)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/__init__.py", line 154, in activate
return self.activation_class.activate(self, prev_activation, token)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 561, in activate
activation.perform()
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 44, in __call__
return self.descriptor(self.instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 112, in __call__
result = self.func(instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 525, in perform
self.activate_next()
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 44, in __call__
return self.descriptor(self.instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 169, in __call__
result = self.func(instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/nodes/ifgate.py", line 24, in activate_next
self.flow_task._on_false.activate(prev_activation=self, token=self.task.token)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/__init__.py", line 154, in activate
return self.activation_class.activate(self, prev_activation, token)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 216, in activate
raise NotImplementedError
NotImplementedError
The problem seem to be that you try to jump to a flow.Start element in the else statement. Please try to jump to e.g. a flow.View element instead.

How to store image files in Amazon S3 and Videos in Vimeo using Django

I want to store the image files in the S3 and the video files in the Vimeo in my django project. I am S3Boto3Storage of Django-storage as the storage backend. As Vimeo takes care of compression and content delivery for video files and it's cheap compared to S3, I want to use that for video files.
I thought of uploading the file to the Vimeo using the upload_to attribute in the FileField of django model, but I can't able to get the absolute path of the video file in the method.
here is my implementation of the upload_to method,
import vimeo
def vimeo_client():
client = vimeo.VimeoClient(
token=settings.VIMEO_ACCESS_TOKEN,
key=settings.VIMEO_CLIENT_ID,
secret=settings.VIMEO_CLIENT_SECRET
)
return client
def get_media_path(instance, filename):
new_filename = '{}.{}'.format(uuid.uuid4(), filename.split('.')[-1])
if instance.type == 'image':
file_path = 'posts/media/images/{filename}'.format(
filename=new_filename)
else:
client = vimeo_client()
file_path = client.upload(
filename,
data={
'name': instance.title,
'description': instance.description
}
)
logger.info("File uploaded to: [{}]".format(file_path))
return file_path
But it's giving me this error
OSError: [Errno 2] No such file or directory: 'videoplayback.mp4'
Or I could customise the S3Boto3Storage for my purpose. I would like to know what would be the better solution.
Edit
Here is the full stack trace
Traceback (most recent call last):
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
response = self.get_response(request)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response
response = self._middleware_chain(request)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
response = response_for_exception(request, exc)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/Users/rohanroy/development/django/zappa/appcore/src/appcore/wsgi.py", line 24, in null_technical_500_response
six.reraise(exc_type, exc_value, tb)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/contrib/admin/options.py", line 551, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 224, in inner
return view(request, *args, **kwargs)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1508, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1408, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1448, in _changeform_view
self.save_model(request, new_object, form, not add)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/contrib/admin/options.py", line 979, in save_model
obj.save()
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/base.py", line 808, in save
force_update=force_update, update_fields=update_fields)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/base.py", line 838, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/base.py", line 924, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/base.py", line 963, in _do_insert
using=using, raw=raw)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/query.py", line 1076, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1112, in execute_sql
for sql, params in self.as_sql():
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1065, in as_sql
for obj in self.query.objs
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1014, in pre_save_val
return field.pre_save(obj, add=True)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/fields/files.py", line 296, in pre_save
file.save(file.name, file.file, save=False)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/fields/files.py", line 93, in save
name = self.field.generate_filename(self.instance, name)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/django/db/models/fields/files.py", line 327, in generate_filename
filename = self.upload_to(instance, filename)
File "/Users/rohanroy/development/django/zappa/appcore/src/utils/common.py", line 50, in get_media_path
'description': instance.description
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/vimeo/upload.py", line 49, in upload
filesize = self.__get_file_size(filename)
File "/Users/rohanroy/development/django/zappa/arete/lib/python2.7/site-packages/vimeo/upload.py", line 163, in __get_file_size
return os.path.getsize(filename)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.py", line 57, in getsize
return os.stat(filename).st_size
OSError: [Errno 2] No such file or directory: 'videoplayback.mp4'
Vimeo API's supports 3 types of video upload strategies which are discussed here. The tus approach assumes that the video file is in the local system. To upload video from the browser one need to use the form-based uploads approach which is not useful for an API only server. There is two option to tackle this,
Upload the video from the client-side to the API server using your own API endpoint and then use vimeo.py to upload it to the Vimeo and delete the actual video file from the server.
Use vimeo.js to upload the video file from the client side and then store the returned video_uri in the backend.

TypeError: string argument expected, got 'bytes' python 3

I have a django app which is running on 1.6 with python 3. Recently I have added django-storages to my app.
When I am trying to save a model(record) which worked well previously, its showing up the below error
Traceback (most recent call last):
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 432, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 198, in inner
return view(request, *args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 29, in _wrapper
return bound_func(*args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 25, in bound_func
return func(self, *args2, **kwargs2)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/transaction.py", line 371, in inner
return func(*args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1131, in add_view
self.save_model(request, new_object, form, False)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 860, in save_model
obj.save()
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 545, in save
force_update=force_update, update_fields=update_fields)
File "/Users/david/.virtualenvs/project/lib/python3.4/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 "/Users/david/.virtualenvs/project/lib/python3.4/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 "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 687, in _do_insert
using=using, raw=raw)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/manager.py", line 232, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/query.py", line 1514, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 902, in execute_sql
for sql, params in self.as_sql():
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 860, in as_sql
for obj in self.query.objs
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 860, in <listcomp>
for obj in self.query.objs
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 858, in <listcomp>
for f in fields
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 252, in pre_save
file.save(file.name, file, save=False)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 87, in save
setattr(self.instance, self.field.name, self.name)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 311, in __set__
self.field.update_dimension_fields(instance, force=True)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 381, in update_dimension_fields
width = file.width
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/images.py", line 17, in _get_width
return self._get_image_dimensions()[0]
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/images.py", line 27, in _get_image_dimensions
self.open()
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 76, in open
self.file.open(mode)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/base.py", line 121, in open
if not self.closed:
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/base.py", line 59, in _get_closed
return not self.file or self.file.closed
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 406, in _get_file
self.key.get_contents_to_file(self._file)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1643, in get_contents_to_file
response_headers=response_headers)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1475, in get_file
query_args=None)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1529, in _get_file_internal
fp.write(bytes)
TypeError: string argument expected, got 'bytes'
model
class RequisitionImage(models.Model, ImageRisizeToolbox):
image_id = models.AutoField(primary_key=True)
requisition = models.ForeignKey(Requisition)
description = models.CharField(max_length=80)
image_file = models.ImageField(upload_to=get_file_path, height_field='image_height', width_field='image_width')
thumbnail_file = models.ImageField(upload_to=get_file_path, blank=True, null=True)
sort_order = models.SmallIntegerField(blank=True, null=True)
filetype = models.CharField(max_length=10, blank=True, null=True)
objects = models.Manager()
cust_objects = RequisitionImageManager()
MAX_SIZE = 4000000 # Image file size limit
def __str__(self):
return self.description
I am getting this error when i am trying to save the RequisitionImage object record both from the admin model and from my view.
So how to avoid this error and what is causing it ?