Bonjour,
J'ai ce message d'erreur que je n'avais pas avant et pourtant j'ai pas modifier cette partie....
Je pense que "unexpected indent" est un problème de formatage? Par exemple si on aligne pas bien un if
Ceci ne marchera pas
ceci marchera si on met bien un tab avant le print
Code PYTHON : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 if isSent is True: print "OK"
Si le premier car génère bien le message "unexpected ident", je pense que mon problème vient de là.
Code PYTHON : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 if isSent is True: print "OK"
J'ai ce code
et ce message quand j'exécute mon scipt
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #preparing the insertion add_position = ("INSERT INTO positions " "(devise_id, imei, timestamp, value, lat, lng, alt, heading, speed, sensor, tower, battery) " "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)") data_position = (devise_id,imei,datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d %H:%M:%S'),value,lat,lng,alt,heading,speed,sensor,tower,battery) # ## connection db = MySQLdb.connect("localhost","root","N0mansland","mqtt") cursor = db.cursor() # http://mysql-python.sourceforge.net/MySQLdb.html#mysqldb ## Insertion try: cursor.execute(add_position, data_position) db.commit() except: db.rollback()
Si mon raisonnement est juste, je n'arrive pas formater correctement ma variable add_position. Pourtant j'ai bien mis des tab représenté par [tab] et des retour représnter par [cr]. J'ai pas mis tout le code de ma fonction. J'ai juste mis ce qui bloque..
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 pierrot@bipme:/var/www/leaflet/rabbit/py$ python receive-new.py File "receive-new.py", line 117 add_position = ("INSERT INTO positions " ^ IndentationError: unexpected indent
Merci pour votre avis
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 def fu(): #...some other code.... [tab]#DEBUG [tab]print('') [tab]print("Devise_id",devise_id) [tab]print("IEMI:",imei) [tab]print("Timestamp:",timestamp) [tab]print("Value:",value) [tab]print("Lat:",lat) [tab]print("Lng:",lng) [tab]if data["position"]["value"] == 1 :[cr] [tab][tab]print("Alt:",alt)[cr] [tab][tab]print("Heading:",heading)[cr] [tab][tab]print("Speed:",speed)[cr] [tab]print("Sensor:",sensor)[cr] [tab]print("Tower:",tower)[cr] [tab]print("Battery:",battery)[cr] [tab]print('')[cr] [cr] [tab]#preparing the insertion [tab]add_position = ("INSERT INTO positions "[cr] [tab][tab]"(devise_id, imei, timestamp, value, lat, lng, alt, heading, speed, sensor, tower, battery) "[cr] [tab][tab]"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")[cr] [tab]data_position = (devise_id,imei,datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d %H:%M:%S'),value,lat,lng,alt,heading,speed,sensor,tower,battery)[cr] # ## connection[cr] [tab]db = MySQLdb.connect("localhost","root","N0mansland","mqtt")[cr] [tab]cursor = db.cursor()[cr] [cr] [tab]# http://mysql-python.sourceforge.net/MySQLdb.html#mysqldb [tab]## Insertion [tab]try: [tab][tab]cursor.execute(add_position, data_position) [tab][tab]db.commit() [tab]except: [tab][tab]db.rollback()
Partager