-1

I am running into an issue I cannot seem to resolve. I have created a Python package containing amongst many things a function inside a class that sends a query to a database and retrieves the results. I also have a seperate program that uses that function. The whole thing looks like this:

Oddjob (seperate python module):

def query(self, query):
    """
    Running a query against Oddjob and returning result
    :param query: The query to run
    :return:
    """
    try:
        qr = self.c.execute(query)
        qry = self.c.fetchall()
    except Exception, e:
        qry = e
    return qry

This ^^^ is what is being called.

The query that needs to be run is kept in a variable as such:

sAvail = "exec sp_avi @week='32'"

And gets called like this:

SAvailability(oddjob.query(str(sAvail)))

Just for information, SAvailability is this code:

def SAvailability(result):
    shipped = result[0]
    onhold = result[1]

    percentWO = 100 / int(shipped)
    percentOnHold = percentWO * int(onhold)
    total = str(int(math.floor(100 - percentOnHold)))

    return total

Please note however, I provide the SAvailability function only for clarification, when I use query together with another function I get the same problem:

TypeError: 'str' object is not callable

The full traceback is:

  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
  return self.wsgi_app(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
  response = self.make_response(self.handle_exception(e))
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
  reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
  response = self.full_dispatch_request()
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
  reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
  rv = self.dispatch_request()
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/arthur/Dropbox/Scaramanga_Development/scaramanga/server.py", line 1062, in dashboard_HEAD
SAvailability(oddjob.query(str(sAvail))),

TypeError: 'str' object is not callable

I have tried adding str() left, right, and centre, but nothing seems to change it. Can anyone see anything obvious I am missing?

  • 1
    Could you provide the full traceback? Which line is causing the error? – jonrsharpe Jul 22 '14 at 11:44
  • 1
    Something you are trying to use as a function, is not a function but a string. Without a full traceback, we can only speculate and guess as to what line this is happening on and what name might be bound to a string. Nothing in the code you shared jumps out, the assignment most likely is done on a line you didn't post. – Martijn Pieters Jul 22 '14 at 11:48
  • Please will you stop disliking the question as 'already been asked'...I have checked the answer and questions asked before, but it does not relate to me as I did not override the str() method. – Xtremesupremacy3 Jul 22 '14 at 12:12

1 Answers1

2

I have tried adding str() left, right, and centre, but nothing seems to change it. Can anyone see anything obvious I am missing?

I guess you some where set str="blablabla".

print type(str) check the result, try del str if print output is str

Gohan
  • 2,422
  • 2
  • 26
  • 45
  • That was also my initial reaction, which seemed unlikely but still. So, I searched through the code, and the only instance at which str is called is as it's function. – Xtremesupremacy3 Jul 22 '14 at 12:08
  • @Xtremesupremacy3 Any discover yet? – Gohan Jul 23 '14 at 02:07
  • Yes, I did. In my case it was down to an external class. For some unknown reason, the following was wrong: `class Connect(query): self.query = query' Once I removed the line 'self.query = query'...the error disappeared – Xtremesupremacy3 Jul 23 '14 at 17:11
  • Is `self.query` original a function? Is `oddjob` a `Connect` class? – Gohan Jul 24 '14 at 01:50
  • No, self.query was simply a variable, one that I don't believe to be a system variable, nor a function. oddjob is an Oddjob class object, and within that class is a function called connect. – Xtremesupremacy3 Jul 24 '14 at 10:25