Girard clément Girard clément - 5 months ago 40
SQL Question

Error "'DefaultConnectionProxy' object has no attribute '__getitem__'" when calling stored procedure

Hi i'm making a project using python/Django, on my first page (index) i'm calling a stored procedure to fetch the data.

def index(request):
listOPT = []
Data = []
fluxState = settings.FLUX_MANAGER_STATE
if fluxState != True:
listOPT.append('FLUX AXEREAL : OFF')
cursor = connection['site'].cursor()
cursor.execute("{CALL SP_webGET_RESUME_MVT_INIT_ACTIF}")
mouvements = cursor.fetchall()
return render(request, 'index.html', locals())

but when executing i get this error "'DefaultConnectionProxy' object has no attribute 'getitem'"

Traceback :


Request Method: GET
Request URL:

Django Version: 1.9.6
Python Version: 2.7.11
Installed Applications:
Installed Middleware:


File "C:\Python27\lib\site-packages\django\core\handlers\" in get_response
149. response = self.process_exception_by_middleware(e, request)

File "C:\Python27\lib\site-packages\django\core\handlers\" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "E:\prog2\PJ1705-027_Automatisation_Silo1_Site_LADON\4-Developpement\Informatique\Web\Gestion_Mouvements\Gestion_Mouvements\Gestion_Mouvement\" in index
26. cursor = connection['site'].cursor()
Exception Type: TypeError at /gestion_mouvement/index
Exception Value: 'DefaultConnectionProxy' object has no attribute '__getitem__'

Any idea on how to fix this ? i saw some people had to add some
def __unicode__
to their models but it doesn't seem to work for me.

Answer Source

It looks like you should be using connections, not connection.

from django.db import connections

cursor = connections['site'].cursor()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download