-2
import bottle, pymongo  
from pymongo import MongoClient 
client = pymongo.MongoClient(some URI)  
db = client['database']  
dbcoll = db['collection']  
@bottle.route('/hello')  
def grab_record(name):  
    bottle.response.headers['Access-Control-Allow-Origin'] = '*'  
    return dbcoll.find_one({'_id':False})  
bottle.run(host='localhost', port=8080, debug=True)  

On opening http://localhost:8080/hello, this is the error I get:

enter image description here

Both bottle.py and this file are on my Desktop. What should I do?

halfer
  • 19,824
  • 17
  • 99
  • 186
glitterati
  • 133
  • 2
  • 16

1 Answers1

2

The parameters in @bottle.route's URL must match the number of arguments in the function that follows it. In your case it doesn't. @bottle.route has no parameters but the function has one (name) argument.

You could either remove name e.g.

def grab_record():  
    bottle.response.headers['Access-Control-Allow-Origin'] = '*'  
    return dbcoll.find_one({'_id':False})  

or alternatively change @bottle.route so that it takes a parameter e.g.

@bottle.route('/hello/<name>') 

depending on your needs.

Robert Longson
  • 118,664
  • 26
  • 252
  • 242
  • { "_id" : ObjectId("kdahfa"), "minTime" : ISODate("2016-04-02T00:00:00.000+0000"), "maxTime" : ISODate("2016-04-02T00:11:00.000+0000"), "Time" : 660.0, "Name" : "Sam" } { "_id" : ObjectId("aabhk"), "minTime" : ISODate("2016-04-02T01:00:00.000+0000"), "maxTime" : ISODate("2016-04-02T02:14:25.000+0000"), "Time" : 4465.0, "Name" : "Bob" } { "_id" : ObjectId("bak"), "minTime" : ISODate("2016-04-02T19:00:00.000+0000"), "maxTime" : ISODate("2016-04-02T19:52:22.000+0000"), "Time" : 3142.0, "Name" : "Sam" } – glitterati May 29 '16 at 10:01
  • This the kind of data that I have. Now I wish to create a Gantt Chart from it on d3.js. First problem, gettin this data on the d3.js and . I am taking help from this example http://bl.ocks.org/dk8996/5449641 Could you please help me here. Your answer helped me getting rid of the error! Thanks for that :) – glitterati May 29 '16 at 10:06
  • As you might've guessed, I'm new to this! – glitterati May 29 '16 at 10:07
  • The code that I've mentioned in the question is to extract the mongodb data to a url. I now wish to use this url to create a d3.js Gantt Chart. – glitterati May 29 '16 at 10:08
  • 1
    @glitterati if you have new questions, ask them separately. I've answered the question you originally asked here. – Robert Longson May 29 '16 at 17:31
  • Thanks a lot. I have asked the question seperately. Please answer if you know this. I have been stuck on this problem for days. – glitterati May 30 '16 at 05:16
  • If you want people to answer your follow-up question, you should accept this answer if it solved the question you did ask. – user3351605 Jun 10 '16 at 17:59