Search code examples
pythongoogle-app-enginewebapp2

unable to get the content of passed parameters in ast module GAE


I have an endpoint from which I am calling webapp post url

Here is endpoint

userId = '14'
data = {"userId" :userId,"a":"s"}
encodedData = urllib.urlencode(data)
result = urlfetch.fetch(url=DELETE_CHANNEL_URL,payload=encodedData,follow_redirects=False,deadline=30,method=urlfetch.POST,
                            headers={'Content-Type': 'application/x-www-form-urlencoded'})

and I am getting this in webapp like

class DeleteChannel(webapp.RequestHandler):
    def post(self):
        logging.info("Delete channel")
        parameters = ast.literal_eval(self.request.body)

        userId  = str(parameters["userId"])
        logging.info('userId' + userId)

but this is showing error

File "/base/data/home/apps/s~dimension-dev-endpoint/1.389460063849645110/Channel.py", line 34, in post
    parameters = ast.literal_eval(self.request.body)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/ast.py", line 49, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/ast.py", line 37, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    a=s&userId=14
     ^
SyntaxError: invalid syntax

what is the issue?


Solution

  • I tried following code the get the userId from paramters and this is working for me

    userId  = self.request.get("userId", default_value='')