Skip to content Skip to sidebar Skip to footer

Html Appengine Redirect Url

I want to redirect a user to the next URL after authenticating on a third party web page. In the redirect URL I want it to contain some info about the user, i.e. session id. For ex

Solution 1:

You want a module called cgi, and a function called FieldStorage. Do it like this:

importcgiurl_parms= cgi.FieldStorage()
session = url_parms.getvalue("session","default")

You can do this for any of the URL parameters. Replace "default" with whatever you want the default value to be (like an empty string).

Solution 2:

Your question is a bit confusing, but is there a reason your other service can not redirect to: www.z.appspot.com/?access_code=x/&token=y&user_id=u? That should be correctly parsed:

import urlparse
import cgi

url = "www.z.appspot.com/?access_code=x/&token=y&user_id=u"
query = urlparse.urlparse(url).query
print cgi.parse_qs(query)
# output: {'access_code': ['x/'], 'token': ['y'], 'user_id': ['u']}

If you can not change the format of the url, you could do something like:

import urlparse
import cgi

url = "www.z.appspot.com/?access_code=x/?token=y&user_id=u"
query = urlparse.urlparse(url).query
access_code, query = query.split('?', 1)
access_code = access_code.split('=', 1)[1]
print access_code
# output: 'x/'print cgi.parse_qs(query)
# output: {'token': ['y'], 'user_id': ['u']}

Or, if you're just trying to ask how to embed parameters in the URL they will be redirected to, see Python's urlencode.

Update:

importurllibencoded= urllib.urlencode({'app_id': 11,
                            'next': 'http://localhost:8086/?access_tok­en=%s' % (access_token,)})
hunch_url = 'http://hunch.com/authorize/v1/?%s' % (encoded,)

Then pass hunch_url to your template.

Solution 3:

It looks like the service you're redirecting to doesn't compose query parameters in the continue URL correctly. The easiest way around this would be (as I suggested in your original question) to send the parameter as part of the path, rather than the query string - that is, use URLs of the form:

http://www.yourapp.com/continue/1234

Where 1234 is the user's session ID or user ID.

Post a Comment for "Html Appengine Redirect Url"