0

I can't seem to find any documentation on how to use twisted.web.util.Redirect to redirect to another function.

For more information see below.

I have the following code:

class Login(Resource):
    isLeaf = True
    def getChild(self, name, request):
        if name == '':
            return self
        return Resource.getChild(self, name, request)

    def render_GET(self, request):
        saml = SamlRequest(request)
        print('redirecting to sso')
        return Redirect(saml.sso())

class SamlRequest(object):
    self.auth = OneLogin_Saml2_Auth(self.request, custom_base_path=settings_path)


    def sso(self):
        return self.auth.login()

I need to redirect to page login to the login function inside OneLogin_Saml2_Auth.

When I try to redirect as-is I receive the error

raise TypeError("Unicode object not allowed as URL")

Is there a way to accomplish this?

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
user1601716
  • 1,893
  • 4
  • 24
  • 53

1 Answers1

1

twisted.web.util.Redirect is a kind of Resource, not something you return from a render method. It's most suitable if you have a "static" redirect that exists in your URL structure and redirects to a fixed location.

If you want to write a custom resource that redirects to a dynamic URL, use twisted.web.util.redirectTo(url, request), which you can call from your render_GET method just like you tried to do with Redirect.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108