Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'json': 0.07; 'python': 0.09; 'received:internal': 0.09; 'subject:create': 0.09; 'subject:script': 0.09; 'subject:trying': 0.09; 'def': 0.10; 'aug': 0.13; 'do,': 0.15; 'to:name:python-list': 0.15; "'this": 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:mail.srv.osa': 0.16; 'received:messagingengine.com': 0.16; 'received:nyi.mail.srv.osa': 0.16; 'received:osa': 0.16; 'received:srv.osa': 0.16; 'subject:simple': 0.16; 'x-mailer:messagingengine.com webmail interface': 0.16; 'string': 0.17; 'trying': 0.21; 'import': 0.21; 'http': 0.22; 'example': 0.23; 'header:In-Reply-To:1': 0.25; 'skip:# 10': 0.27; 'skip:@ 10': 0.27; 'run': 0.28; 'post': 0.28; 'request,': 0.29; "skip:' 10": 0.30; 'to:addr:python-list': 0.33; 'subject:: ': 0.38; 'easier': 0.38; 'received:10': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'back': 0.62; 'header:Message-Id:1': 0.62; 'receive': 0.71; 'bottle': 0.84 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.fm; h= message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:references:subject:date; s=mesmtp; bh= TGE8DZ5L1KVMnqTS41hiL/5qknc=; b=LzYl0JTNJ7yDnn2saLIOUF2gEHavMLyl QSACmupKR3KTtt0aj3lKv1iwayva6dB12GwdVup9xCOpp6x19KCymFBr3aj6SiO6 HqoVW6PkSIhrCoE7qE0nWN052ISupp6yudIn0rTrFECR+NhE1rSNNxPdyQKkdkPC 3ChuPPcCEwI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=TGE8DZ5L1KVMnqTS41hiL/5qknc=; b=YAF 3L5eU5DyljbAa3AUcSCmFPWLGNn7IVK1flS+kH5FsLI6n3uTUW8ftjYavErBMPqP IGJWPvprJR+N2GwViQ8Nxyi1b0g8w/ahM3OGYivy54vAdXR18eyAlHZmRctgzcOQ XSZoelZuIk1gaLLoGPQ3Edn/T22RFee4frU/5ajI= X-Sasl-Enc: Tn6SF2ZxdC6uFOl/xtQgqmEZIfu5KVRPWsfBfoqOklkF 1344580526 From: Lutz Horn To: "python-list" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: References: Subject: Re: trying to create simple py script Date: Fri, 10 Aug 2012 08:35:26 +0200 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344580529 news.xs4all.nl 6970 [2001:888:2000:d::a6]:49009 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26841 Hi Smaran, Am Do, 9. Aug 2012, um 23:52, schrieb Smaran Harihar: > I am trying to create a simple cgi-script to receive a Ajax > call, manipulate the string received and send it back as JSON. I can recommend bottle. The following example manipulates a JSON request body and returns it. That is *much* easier than using CGI. #!/usr/bin/env python from bottle import request, post, run @post('/hello') def index(): if request.headers.get('X-Requested-With') == 'XMLHttpRequest': body = request.json body["baz"] = "qux" return body else: return 'This is a normal HTTP Post request.' run(host='localhost', port=8080) Lutz