Bonjour,
J'ai une page web qui doit m'afficher une liste de noms (un explorateur de fichierstyle iphone en gros), j'ai installé wamp et le module wsgi pour coder ma partie serveur en python
Le tout discute par l’intermédiaire de requêtes AJAX et d'objets JSON. Lors de tests de l'interface client-serveur avec des valeurs en carton j'arrivais a afficher et a parcourir les fichiers.
Maintenant je dois récupérer des valeurs dans ma base de données j'ai créé une interface serveur bdd en python. Pour cela j'ai téléchargé le module mysqldb pour python. Cette interface fonctionne parfaitement dans une console python (2.7).
Le probleme arrive lorsque je lance ma page web, au debut j'ai eu des problemes d'importations de fichiers python , puis maintenant mon log apache me donne cette erreur:L'erreur finale m'indique erreur de syntaxe pres de '['0']' mais a aucune ligne 1 de mes fichiers j'ai un '['0']'mod_wsgi (pid=5024): Exception occurred processing WSGI script 'C:/Users/Admin/work_cordova/vmobile/www/wsgi-scripts/myapp.wsgi'., referer: http://localhost/html/zones.html
Traceback (most recent call last):, referer: http://localhost/html/zones.html
File "C:/Users/Admin/work_cordova/vmobile/www/wsgi-scripts/myapp.wsgi", line 156, in application, referer: http://localhost/html/zones.html
return doGet(environ, start_response), referer: http://localhost/html/zones.html
File "C:/Users/Admin/work_cordova/vmobile/www/wsgi-scripts/myapp.wsgi", line 124, in doGet, referer: http://localhost/html/zones.html
return doDataNodeNavigation(environ, start_response), referer: http://localhost/html/zones.html
File "C:/Users/Admin/work_cordova/vmobile/www/wsgi-scripts/myapp.wsgi", line 25, in doDataNodeNavigation, referer: http://localhost/html/zones.html
l = getDataNodeChildren(parent_id), referer: http://localhost/html/zones.html
File "C:\\Users\\Admin\\work_cordova\\vmobile\\www\\wsgi-scripts\\interface_py_sql.py", line 19, in getDataNodeChildren, referer: http://localhost/html/zones.html
cur.execute(sql), referer: http://localhost/html/zones.html
File "C:\\Python27\\lib\\site-packages\\MySQLdb\\cursors.py", line 202, in execute, referer: http://localhost/html/zones.html
self.errorhandler(self, exc, value), referer: http://localhost/html/zones.html
File "C:\\Python27\\lib\\site-packages\\MySQLdb\\connections.py", line 36, in defaulterrorhandler, referer: http://localhost/html/zones.html
raise errorclass, errorvalue, referer: http://localhost/html/zones.html
ProgrammingError: (1064, "Erreur de syntaxe pr\\xe8s de '['0']' \\xe0 la ligne 1"), referer: http://localhost/html/zones.html
voici mon code python de la fonction getDataNodeChildren qui doit recuperer des objets datanodes a partir de l'id d'un autre datanode :
voici le constructeur et les methodes de Datanode :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 def getDataNodeChildren(parentid): sql = "SELECT * FROM datanodes where par_id = {}".format(parentid) cur.execute(sql) dndList=[] for row in cur.fetchall() : #dnd prototype : id, type_id, label, parent_id dnd = DataNode( row[0], row[3], row[2], parentid) dndList.append(dnd) return dndList*EDIT* J'ai reussi a reproduire l'erreur dans phpmyadmin avec cette requete :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 class DataNode: def __init__(self, dnd_id, dnd_type_id, dnd_label,dnd_parent_id): self.dnd_id = dnd_id self.dnd_type_id = dnd_type_id self.dnd_label = dnd_label self.dnd_parent_id = dnd_parent_id def toString(self): strng = "id : %i, label : %s, type : %i, parent id :%i" % (self.dnd_id,self.dnd_label,self.dnd_type_id,self.dnd_parent_id) print(strng) def toJSONObject(self): return {"id":self.dnd_id,"type":self.dnd_type_id,"label":self.dnd_label,"parentid":self.dnd_parent_id}
Je ne sais pas d'ou viennent les crochets, mais du coup j'ai essayé plusieurs syntaxes, la requete fonctionne avec 0, '0', '{0}' , '[0]', "['0']" et "0" ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part SELECT * FROM datanodes where par_id = ['0']'
Voila si vous avez besoin de precisions n'hesitez pas je suis en ligne, si j'ai du nouveau je vous tiens au courant.
Partager