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

Follow 301 redirect from API #69

Open
vasekch opened this issue Oct 16, 2020 · 1 comment
Open

Follow 301 redirect from API #69

vasekch opened this issue Oct 16, 2020 · 1 comment

Comments

@vasekch
Copy link

vasekch commented Oct 16, 2020

I've successfully connected two django apps using django-rest-models 1.9.2, but I was facing following issue

When I've left everything in default as per tutorials (rest_framework and dynamic_rest on API server side and rest_models on client side) I was unable to run client application due to error:

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
services.ServiceBase: (rest_models.E001) the remote api does not respond to us. OPTIONS http://localhost:8000/servicebase => 301
	HINT: check the url for the remote api or the resource_path

It's because request is lacking the trailing slash. So API server responds with 301 redirect, but rest_models fail, because it's not 200 -

if res.status_code != 200:
. Is it possible to follow redirects somehow?

To bypass this I've changed my API - passed extra parameter to router constructor in urls.py (bellow). But I'd prefer original behavior.

...
from rest_framework import routers

router = routers.DefaultRouter(trailing_slash=False)
router.register(r'servicebase', views.ServiceBaseViewSet)

urlpatterns = [
    path('', include(router.urls)),
...

Thanks!

@vasekch vasekch changed the title 301 redir handling Follow 301 redirect from API Oct 16, 2020
@vasekch
Copy link
Author

vasekch commented Nov 18, 2020

Just a note.

According to requests docs it should follow 301 redirect automatically for GET, OPTIONS, POST, PUT, PATCH or DELETE. Only where you need to explicitly enable it is HEAD.

But I'm not sure how exactly we use requests and if we should change something under ApiVerbShortcutMixin in

class ApiVerbShortcutMixin(object):

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

1 participant