0

I have defined multplie service urls , all of which will execute same code.

@service.route('/get_info/env=<path:env>/starttime=<int:starttime>/endtime=<int:endtime>/entire=<entire>/over=<over>/stage=<stage>', defaults={'name': None}, strict_slashes=False)
@service.route('/get_info/dir=<path:dir>/starttime=<int:starttime>/endtime=<int:endtime>/entire=<entire>/over=<over>', defaults={'stage': 'ABC', 'name': None}, strict_slashes=False)

@servicelog.operation('GetInfo')
def get_deployment_info(env, starttime, endtime, finished, stage, fleetwide, hostname):
global _misc
try:
    log.info("Dir: %s, Starttime: %d, Endtime: %d, name: %s, finished:%s, Stage:%s, Fleetwide: %s", dir, starttime, endtime, name,over, stage, entire)
    result = obj.get_info(dir, starttime, endtime, entire, over, stage, name)

If I were to invoke the service with below parameters, it works as expected:

http://<endpoint>/get_info/dir=home/user/test/starttime=1470439200/endtime=1470856027/entire=true/over=true

However if I get invoke the service with below parameters, I get a re-direct message:

http://<endpoint>/get_info/dir=home/user/test/starttime=1470439200/endtime=1470856027/entire=true/over=true/stage=ABC

The error I get is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="http://endpoint/get_info/dir%3Dhome/user/test/starttime%3D1470439200/endtime%3D1470856027/entire%3Dtrue/over%3Dtrue">http://endpoint/get_info/dir%3Dhome/user/test/starttime%3D1470439200/endtime%3D1470856027/entire%3Dtrue/over%3Dtrue</a>.  If not click the link.%    

Am I doing something incorrect here? I am not expecting such a message as I have not defined any sort of redirection. It should execute the method irrespective of which url is used.

alwaysAStudent
  • 2,110
  • 4
  • 24
  • 47

1 Answers1

0

The way you construct the route is not really clean. GET request with arguments should take the format of http://server/route?arg1=val1&arg2=val2&.. etc. I'm pretty sure some special character or some parsing issue is responsible of the error here.

Use request.args.get('arg1') to retrieve the parsed argument 1's value (Don't forget from flask import request at the top) in your GET request handler. To get the whole string use request.query_string

Look at this SO question.

Community
  • 1
  • 1
GG_Python
  • 3,436
  • 5
  • 34
  • 46
  • Thanks for your reply. Did some more digging around. It happens if I pass `stage=ABC`, and I have defined the default value of stage as ABC for the second alternate url. Not sure why it tries to read the second alternate url's defaults though. It works for all other values. – alwaysAStudent Aug 11 '16 at 22:38