Thanks a lot. The typo was the actual error.

The external application is now running. But I am getting an error, bad
return value. I have attached the output alongwith my python source.

I would also like to know some library through which it is easy to handle
JSON requests and responses in C. Basically I have to check the JSON request
for a *ready* flag in my external application (which will be in C), do some
processing, and send a JSON response with a *successful* flag.

Regards.




On Mon, May 31, 2010 at 3:33 PM, Dave Cottlehuber <[email protected]> wrote:

> On 31 May 2010 21:31, Mahendra Kariya <[email protected]> wrote:
> > I am running couchdb from root user. The command that I specified in
> > my_process is working in root.
> >
> > CouchDB log says
> > [info] [<0.95.0>] 127.0.0.1 - - 'GET' /microatm/my_process 404
>
> Try this instead:
>
> $ curl http://127.0.0.1:5984/microatm/_my_process
>
> Your httpd_db_handler URL is the first parameter in the ini file, not
> the <<"my_process">> bit, which is a pointer for couchdb to find the
> actual script in the [external] section.
>
> If you have the following diff against local.ini:
>
> > [external]
> > mango = /opt/local/bin/couch_external_process.py
> >
> > [httpd_db_handlers]
> > _test = {couch_httpd_external, handle_external_req, <<"mango">>}
> >
>
> your URL is /microatm/_test
> and not /microatm/mango or /microatm/_mango
>
> when I try an incorrect URL I get your error:
> d...@continuity:/Users/dave $ curl http://localhost:5984/sofa/mango
>
> {"error":"not_found","reason":"missing"}
> d...@continuity:/Users/dave $ curl http://localhost:5984/sofa/_mango
>
> {"error":"not_found","reason":"missing"}
> but the correct URL is fine:
> d...@continuity:/Users/dave $ curl http://localhost:5984/sofa/_test
>                                              {"qs":{}}%
>
> you also seem to have a typo in your local.ini file from above -
> you've got a double _underscore_ in httpd_db_handler.
>
> _my__process should really be
> _my_process
>
> A+
> Dave
>
import sys

try:
	import json
except:
	import simplejson as json

def requests():
	line = sys.stdin.readline()
	while line:
		yield json.loads(line)
		line = sys.stdin.readline()
		
def respond(code = 200,data={}, headers={}):
	sys.stdout.write("%s\n" % json.dumps({"code":code,"json":data,"headers":headers}))
	sys.stdout.flush()
	
def main():
	for req in requests():
		respond(data={"qs": req["query"]})

if __name__ == "__main__":
	main()	
	

Reply via email to