无法获取ast模块GAE中传递参数的内容
unable to get the content of passed parameters in ast module GAE
我有一个调用 webapp 的端点 post url
这是端点
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'})
我在 webapp 中得到了这个
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)
但这显示错误
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
有什么问题?
我尝试按照代码从参数中获取 userId,这对我有用
userId = self.request.get("userId", default_value='')
我有一个调用 webapp 的端点 post url
这是端点
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'})
我在 webapp 中得到了这个
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)
但这显示错误
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
有什么问题?
我尝试按照代码从参数中获取 userId,这对我有用
userId = self.request.get("userId", default_value='')