I have a django rest Backend app, and i use swagger to look and document my apis to the FE.
This worked fine, but I made some changes and now I get this error:
Internal Server Error: /
Traceback (most recent call last):
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/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/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/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/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 497, in dispatch
response = self.handle_exception(exc)
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 457, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 468, in raise_uncaught_exception
raise exc
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 494, in dispatch
response = handler(request, *args, **kwargs)
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework_swagger/views.py", line 32, in get
schema = generator.get_schema(request=request)
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/schemas/coreapi.py", line 153, in get_schema
links = self.get_links(None if public else request)
File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/schemas/coreapi.py", line 140, in get_links
link = view.schema.get_link(path, method, base_url=self.url)
AttributeError: 'AutoSchema' object has no attribute 'get_link'
HTTP GET / 500 [0.15, 127.0.0.1:44214]
/home/notsoshabby/Desktop/panda_pitch/django_project/settings.py
This error is not very clear as the AutoSchema is not a part of my code and the traceback is not showing me where in My code the problem is.
I made too many changes to go one by one and check which one caused that.
Anyone experienced this issue before? Any ideas on how to debug to find which change causes this issue?
I ran into the same issue, the fix is described here: https://www.django-rest-framework.org/community/3.10-announcement/
To summarize, Django Rest Framework 3.10 (released a few days ago) deprecated the CoreAPI based schema generation, and introduced the OpenAPI schema generation in its place. Currently to continue to use django-rest-swagger as is you need to re-enable the CoreAPI schema generation by adding the following config to the settings file:
REST_FRAMEWORK = { ... 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' }
Related
Issue Summary
Install Wagtail with all required dependencies. In order to use a GIF, WAND and imagemagick must be installed.
All steps have been implemented as specified in the documentation. (https://docs.wagtail.org/en/stable/advanced_topics/images/animated_gifs.html)
It seems like too much frames in the GIF will cause the error. I tried it with a GIF with less frames and it worked.
Unfortunately, the GIF handling with Wagtail currently does not work must be set more, which is not documented?
When uploading a GIF file I now get the following error message:
Error Message
2022-08-23 10:29:53,630 ERROR [django.request:241] log 73 140094513477440 Internal Server Error: /admin/images/multiple/add/
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.8/site-packages/django/views/decorators/cache.py", line 62, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/wagtail/admin/urls/__init__.py", line 161, in wrapper
return view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/wagtail/admin/auth.py", line 182, in decorated_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 84, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/utils/decorators.py", line 46, in _wrapper
return bound_method(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/views/decorators/vary.py", line 21, in inner_func
response = func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/wagtail/admin/views/generic/multiple_upload.py", line 44, in dispatch
return super().dispatch(request)
File "/usr/local/lib/python3.8/site-packages/wagtail/admin/views/generic/permissions.py", line 36, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 119, in dispatch
return handler(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/wagtail/admin/views/generic/multiple_upload.py", line 144, in post
if form.is_valid():
File "/usr/local/lib/python3.8/site-packages/django/forms/forms.py", line 205, in is_valid
return self.is_bound and not self.errors
File "/usr/local/lib/python3.8/site-packages/django/forms/forms.py", line 200, in errors
self.full_clean()
File "/usr/local/lib/python3.8/site-packages/django/forms/forms.py", line 433, in full_clean
self._clean_fields()
File "/usr/local/lib/python3.8/site-packages/django/forms/forms.py", line 443, in _clean_fields
value = field.clean(value, bf.initial)
File "/usr/local/lib/python3.8/site-packages/django/forms/fields.py", line 670, in clean
return super().clean(data)
File "/usr/local/lib/python3.8/site-packages/django/forms/fields.py", line 198, in clean
value = self.to_python(value)
File "/usr/local/lib/python3.8/site-packages/wagtail/images/fields.py", line 122, in to_python
self.check_image_pixel_size(f)
File "/usr/local/lib/python3.8/site-packages/wagtail/images/fields.py", line 112, in check_image_pixel_size
self.error_messages["file_too_many_pixels"] % (num_pixels),
ValueError: unsupported format character ')' (0x29) at index 33
Steps to Reproduce
Install Wagtail with all the libraries in techincal details
I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes
Technical details
Django>=4.0,<4.1
wagtail>3
wagtail_localize==1.2.1
django-extensions==3.2.0
psycopg2==2.9.3
loglevel==0.1.2
Wand==0.6.10
Ubunutu Server: sudo apt-get install libmagickwand-dev
Local MacOS: brew install imagemagick
Thank you very much in advance.
I look forward to your feedback.
I found the problem: WAGTAILIMAGES_MAX_IMAGE_PIXELS = 128000000.
I had to set the WAGTAILIMAGES_MAX_IMAGE_PIXELS higher than the default.
I am using django rest_framework_swagger for my django project, everything was working fine but when I added some URLs with include method Swagger start giving me 500 internal server error.
I am not sure why this error is coming, I have checked but didn't find anything to fix this error.
I am using:
django 1.11.7
rest_framework_swagger 2.1.2
django rest framework 3.7.3
URLs
from django.conf.urls import url, include
from link_one.views import LinkOneViewSet
from link_two.views import LinkTwoViewSet
schema_view = get_swagger_view(title='My Project APIs')
urlpatterns = [
url(r'^$', schema_view),
url(r'^foo/(?P<foo_id>\w+)/bar/(?P<bar_id>\w+)/link1',
LinkOneViewSet.as_view({'get': 'list'})),
url(r'^foo/(?P<foo_id>\w+)/bar/(?P<bar_id>\w+)/link2',
LinkTwoViewSet.as_view({'get': 'list'})),
url(r'^foo/(?P<foo_id>\w+)/bar/(?P<bar_id>\w+)/link3',
include('link_three.urls'))
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Error
[25/Jan/2021 14:03:31] ERROR [django.request.exception:135] Internal Server Error: /
Traceback (most recent call last):
File "C:\Users\myuser\conda_env\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
response = get_response(request)
File "C:\Users\myuser\conda_env\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\myuser\conda_env\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\myuser\conda_env\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\myuser\conda_env\lib\site-packages\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework\views.py", line 489, in dispatch
response = self.handle_exception(exc)
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework\views.py", line 449, in handle_exception
self.raise_uncaught_exception(exc)
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework\views.py", line 486, in dispatch
response = handler(request, *args, **kwargs)
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework_swagger\views.py", line 32, in get
schema = generator.get_schema(request=request)
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework\schemas\generators.py", line 278, in get_schema
links = self.get_links(None if public else request)
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework\schemas\generators.py", line 316, in get_links
link = view.schema.get_link(path, method, base_url=self.url)
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework\schemas\inspectors.py", line 179, in get_link
fields += self.get_serializer_fields(path, method)
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework\schemas\inspectors.py", line 302, in get_serializer_fields
serializer = view.get_serializer()
File "C:\Users\myuser\conda_env\lib\site-packages\rest_framework\generics.py", line 112, in get_serializer
return serializer_class(*args, **kwargs)
TypeError: 'list' object is not callable
After searching a lot and debugging, I have found a solution for this.
The solution is, don't use multiple serializer classes for a ViewSet.
In my one viewset I was doing this and this is what creating the problem.
class FooBarViewset(ModelViewSet):
serializer_class = [DefaultSerializer, BarSerializer, FooSerializer]
But I did not realize that this will cause the error.
Here is Fix that I am using
class FooBarViewset(ModelViewSet):
serializer_class = DefaultSerializer
You can also use the get_serializer method and map serializer class with an action, please check this answer Django rest framework, use different serializers in the same ModelViewSet
This is the query:
comment = AdditionalComment.objects.get(form = form, student = students[student])
and works perfectly on my local machine.
Ive deployed the project to a DO VPS and whenever I try access the view i get this error even though I can see the AdditionalComment in the admin panel:
File "/home/smartsurvey/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/smartsurvey/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/smartsurvey/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/smartsurvey/venv/lib/python3.6/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/home/smartsurvey/smart-survey/forms/views.py", line 195, in view_replies
comment = AdditionalComment.objects.get(form = form, student = students[student])
File "/home/smartsurvey/venv/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/smartsurvey/venv/lib/python3.6/site-packages/django/db/models/query.py", line 380, in get
self.model._meta.object_name
forms.models.DoesNotExist: AdditionalComment matching query does not exist.`
Any idea what it could be? let me know if you need anymore info
I realised I was querying the database for users comments before they had made them, so I added an if statement checking if they had replied.
Error says: there is no AdditionalComment with such parameters. You need create AdditionalComment instance, and after you can get it.
I just updated my code from django 1.8 to 1.11 and so i also had to update tasty pie. Before update everything worked fine but now I am getting this error on one of my tests.
Here is the test case
def test_does_not_return_restricted_fields_when_insufficient_permissions(self):
self.user.user_permissions.all().delete()
response = self.api_client.get(url,
format='json',
authentication=self.create_apikey(username=self.username, api_key=self.api_key),
data=data)
Here is the full Trace,
Traceback (most recent call last):
File "/spare/local/projects/towerportal/apps/exchangedb/tests/test_api.py", line 68, in test_does_not_return_restricted_fields_when_insufficient_permissions
response = self.get_response(self.detail_url)
File "/spare/local/projects/towerportal/apps/exchangedb/tests/test_api.py", line 26, in get_response
data=data)
File "/spare/local/venv/lib/python2.7/site-packages/tastypie/test.py", line 70, in get
return self.client.get(uri, **kwargs)
File "/spare/local/venv/lib/python2.7/site-packages/django/test/client.py", line 536, in get
**extra)
File "/spare/local/venv/lib/python2.7/site-packages/django/test/client.py", line 340, in get
return self.generic('GET', path, secure=secure, **r)
File "/spare/local/venv/lib/python2.7/site-packages/django/test/client.py", line 416, in generic
return self.request(**r)
File "/spare/local/venv/lib/python2.7/site-packages/django/test/client.py", line 501, in request
six.reraise(*exc_info)
File "/spare/local/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/spare/local/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/spare/local/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/spare/local/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/spare/local/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner
return func(*args, **kwargs)
File "/spare/local/venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/spare/local/venv/lib/python2.7/site-packages/tastypie/resources.py", line 221, in wrapper
response = callback(request, *args, **kwargs)
File "/spare/local/venv/lib/python2.7/site-packages/tastypie/resources.py", line 470, in dispatch_detail
return self.dispatch('detail', request, **kwargs)
File "/spare/local/venv/lib/python2.7/site-packages/tastypie/resources.py", line 493, in dispatch
response = method(request, **kwargs)
File "/spare/local/venv/lib/python2.7/site-packages/tastypie/resources.py", line 1376, in get_detail
obj = self.cached_obj_get(bundle=basic_bundle, **self.remove_api_resource_names(kwargs))
File "/spare/local/venv/lib/python2.7/site-packages/tastypie/resources.py", line 1195, in cached_obj_get
cached_bundle = self.obj_get(bundle=bundle, **kwargs)
File "/spare/local/venv/lib/python2.7/site-packages/tastypie/resources.py", line 2176, in obj_get
applicable_filters = self.build_filters(filters=kwargs, ignore_bad_filters=True)
TypeError: build_filters() got an unexpected keyword argument 'ignore_bad_filters'
Could your please paste your tastypie resource code?
Without related code, I can only guess that it is because you override
def build_filters(): in your modelresource class, but the newer version of tastypie added a ignore_bad_filter parameter in the function definition which you do not have in your modelresource code.
The build_filters function declaration in the latest tastypie:
def build_filters(self, filters=None, ignore_bad_filters=False):
The old version probably does not have the ignore_bad_filter parameter. To fix this, just add ignore_bad_filters=Falsekey word parameter to the build_filters function in your modelresource class.
I have a Django REST server which I updated recently from using Python 2.7 to 3.4. The server uses Django REST framework on top of Django, with django-allauth and django-rest-auth for Facebook login support.
Now, after the update, I cannot login to the server with Facebook anymore. When I send a POST to the server, I get the following error:
Internal Server Error: /rest-auth/facebook/
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\core\handlers\base.py", line 132, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python34\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view return view_func(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\views\generic\base.py", line 71, in view return self.dispatch(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\rest_framework\views.py", line 452, in dispatch response = self.handle_exception(exc)
File "C:\Python34\lib\site-packages\rest_framework\views.py", line 449, in dispatch response = handler(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\rest_auth\views.py", line 51, in post if not self.serializer.is_valid():
File "C:\Python34\lib\site-packages\rest_framework\serializers.py", line 187, in is_valid self._validated_data = self.run_validation(self.initial_data)
File "C:\Python34\lib\site-packages\rest_framework\serializers.py", line 370, in run_validation value = self.validate(value)
File "C:\Python34\lib\site-packages\rest_auth\registration\serializers.py", line 31, in validate token.account = login.account
File "C:\Python34\lib\site-packages\django\db\models\fields\related.py", line 668, in __set__ (value, self.field.rel.to._meta.object_name)
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 496, in __repr__ u = six.text_type(self)
File "C:\Python34\lib\site-packages\allauth\socialaccount\models.py", line 104, in __str__ return force_text(self.user)
File "C:\Python34\lib\site-packages\django\db\models\fields\related.py", line 608, in __get__ "%s has no %s." % (self.field.model.__name__, self.field.name)
django.db.models.fields.related.RelatedObjectDoesNotExist: SocialAccount has no user.
[13/Apr/2015 08:53:30]"POST /rest-auth/facebook/ HTTP/1.1" 500 115908
What could be causing this? I have done no changes to the code after updating Python and the libraries, and it worked before the update. I deleted the old database and created a new one via syncdb but it didn't help.
Thanks in advance.
RelatedObject has been removed in Django 1.8 in favour of ForeignObjectRel. Source
The allauth version you are using does not support Django 1.8.