Erreur d'indentation Python ?
Résolu
Lyunalia
Messages postés
6
Statut
Membre
-
Lyunalia Messages postés 6 Statut Membre -
Lyunalia Messages postés 6 Statut Membre -
Bonjour,
Je veux créer une boucle pour envoyer des mails en récupérant des infos sur une base de données. Problème, une partie du programme ne se prend pas dans la boucle "for" de mon programme.
Aidez-moi s'il vous plait !
Je veux créer une boucle pour envoyer des mails en récupérant des infos sur une base de données. Problème, une partie du programme ne se prend pas dans la boucle "for" de mon programme.
Aidez-moi s'il vous plait !
import smtplib, ssl from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import pymysql.cursors import os # YAY ON EST CO LA C'EST BIEN baseDeDonnees = pymysql.connect(host='127.0.0.1', user='root', db='marchestp', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) print ("YAY ON EST CO") #####################################SELECTIONNER LES CRITERES ICI, ON AMELIORERA APRES############################################################## curseur = baseDeDonnees.cursor() curseur.execute("SELECT Mail, Nom, Prenom FROM feuille_de_calcul_sans_titre___feuille_1 WHERE Envoi = 'x'") myresult = curseur.fetchall() ############################################## on rentre les renseignements pris sur le site du fournisseur smtp_address = 'smtp.gmail.com' smtp_port = 465 # on rentre les informations sur notre adresse e-mail email_address = 'E******@gmail.com' email_password = '*****' # on rentre les informations sur le destinataire ########################################ON COMMENCE LA BOUCLE########################################## for chaine in myresult: email_receiver = chaine["Mail"] Nom = chaine["Nom"] Prenom = chaine["Prenom"] Mail = chaine["Mail"] #print(Mail,Nom,Prenom) # on crée un e-mail message = MIMEMultipart("alternative") # on ajoute un sujet message["Subject"] = "SolareWatt Lodévois" # un émetteur message["From"] = email_address # un destinataire message["To"] = 'spammed327@gmail.com' # on crée un texte et sa version HTML texte = ''' Bonjour Coucou on peut utiliser ce logiciel pour des souscriptions automatiques Cdt Parfait ''' #ici on va mettre le texte dans le mail if "gmail.com" in email_receiver: html = ''' <html> <body> <h1>Bonjour {Nom} {Prenom}</h1> <p>Ecolodeve vous remercie pour votre souscription au projet SolaireWatt</p> <br> S'il vous manque des documents, ils vont s'afficher ci-dessous : < b></b> <br>{id_card} {RIB} {justification} {bon} <br> <p>Merci à vous !</p> <br> <br><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAT4AAACfCAMAAABX0UX9AAABJlBMVEX//////v////3xfwH9///xfAAAL2DxgADxegAALFzweAAAI1jwfQAAKVsuSXH88N7ymEsbQ23+/fj79enh5+zS2uHx9PZEYoIAMF/xhQD1uIQoQWrCytXvcgAAH1YAKFv0sHT23cH1wID0p******8BluSF17d/JZwAAAAASUVORK5CYII="> Je suis un gentil bot ! pardonnez mes bugs, mon créateur est un débutant ! <br> <img style="position:absolute;top:0.86in;left:0.45in;width:2.58in;height:1.38in" src="https://i.ibb.co/wYDtpjT/ri-1.png" /> <img style="position:absolute;top:8.46in;left:0.88in;width:2.55in;height:0.92in" src="https://i.ibb.co/Trh6vrx/ri-2.png" />'''.format(**locals()) else: html = ''' <head> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <div style="position:absolute;top:11.43in;left:3.54in;width:1.97in;line-height:0.12in;"><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000">SAS SOLAIREWATT LODEVOIS</span><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:11.59in;left:2.92in;width:3.21in;line-height:0.12in;"><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:Times New Roman;color:#000000">Société par actions simplifiée au capital variable de 5000€</span><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:11.74in;left:3.12in;width:2.82in;line-height:0.12in;"><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000">Numéro Siret : 89229979300018-RCS Montpellier</span><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:11.90in;left:3.76in;width:1.54in;line-height:0.12in;"><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000">906 avenue Paul Teisserenc</span><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:12.06in;left:4.12in;width:0.82in;line-height:0.12in;"><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000">34700 Lodève</span><span style="font-style:normal;font-weight:normal;font-size:9pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:2.24in;left:4.94in;width:1.14in;line-height:0.17in;"><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000">{Nom} {Prenom}</span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:2.45in;left:4.94in;width:1.34in;line-height:0.17in;"><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000">On met l'adresse plus tard dac ?</span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:2.66in;left:4.94in;width:0.50in;line-height:0.17in;"><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000">34290</span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:2.87in;left:4.94in;width:0.60in;line-height:0.17in;"><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000">Servian</span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:3.92in;left:6.24in;width:1.97in;line-height:0.15in;"><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000">Lodève, le jeudi 8 avril 2021</span><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:4.95in;left:3.13in;width:2.79in;line-height:0.15in;"><span style="font-style:normal;font-weight:bold;font-size:11pt;font-family:TimesNewRomanPS-BoldMT;color:#000000">SOUSCRIPTION AU PROJET SOLAIREWATT</span><span style="font-style:normal;font-weight:bold;font-size:11pt;font-family:TimesNewRomanPS-BoldMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:5.36in;left:0.86in;width:6.58in;line-height:0.15in;"><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000">Nous confirmons votre souscription de </span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000">1</span><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000"> part(s) au capital social de la SAS Solairewatt Lodévois.</span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:5.57in;left:0.86in;width:5.75in;line-height:0.15in;"><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000">Grâce à votre apport, la Région Occitanie versera également, la somme de </span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000">100</span><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000"> euros.</span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:5.97in;left:0.86in;width:7.29in;line-height:0.15in;"><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000">Cependant, il vous reste quelque(s) document(s) à envoyer</span><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:7.37in;left:0.86in;width:2.74in;line-height:0.15in;"><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000">Un grand merci pour votre participation.</span><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:7.96in;left:0.86in;width:0.90in;line-height:0.15in;"><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000">Marc Padilla</span><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <div style="position:absolute;top:8.15in;left:0.86in;width:1.95in;line-height:0.15in;"><span style="font-style:normal;font-weight:normal;font-size:11pt;font-family:TimesNewRomanPSMT;color:#000000">P/SAS Solairewatt Lodévois</span><span style="font-style:normal;font-weight:normal;font-size:12pt;font-family:TimesNewRomanPSMT;color:#000000"> </span><br/></SPAN></div> <img style="position:absolute;top:0.86in;left:0.45in;width:2.58in;height:1.38in" src="https://i.ibb.co/wYDtpjT/ri-1.png" /> <img style="position:absolute;top:8.46in;left:0.88in;width:2.55in;height:0.92in" src="https://i.ibb.co/Trh6vrx/ri-2.png" /> </body> </html> '''.format(**locals()) # on crée deux éléments MIMEText texte_mime = MIMEText(texte, 'plain') html_mime = MIMEText(html, 'html') # on attache ces deux éléments message.attach(texte_mime) message.attach(html_mime) # on crée la connexion context = ssl.create_default_context() with smtplib.SMTP_SSL(smtp_address, smtp_port, context=context) as server: # connexion au compte server.login(email_address, email_password) # envoi du mail server.sendmail(email_address, 'spammed327@gmail.com', message.as_string()) #email_receiver # Nom = Nom +'.txt' # data=open(Nom,'w+') # data.write(id_card+RIB+justification+bon) # data.close() print('Mail envoyé')
Configuration: Windows / Chrome 90.0.4430.212
A voir également:
- Erreur d'indentation Python ?
- Citizen code python - Accueil - Outils
- Erreur 0x80070643 - Accueil - Windows
- Erreur 4201 france tv ✓ - Forum Réseaux sociaux
- Python pix ✓ - Forum Python
- J'aime par erreur facebook notification - Forum Facebook
5 réponses
bonjour,
quelle partie ne prend pas?
n'oublie pas de préciser le langage quand tu utilises les balises de code: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
le cas échéant, ajoute des print() pour suivre ce que fait ton code.
quelle partie ne prend pas?
n'oublie pas de préciser le langage quand tu utilises les balises de code: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
le cas échéant, ajoute des print() pour suivre ce que fait ton code.
j'ai un problème d'indentation à chaque ligne. Il veut que je supprime l'indentation mais je veux rester dans la boucle for :/
J'ai ce message chaque ligne... Moi non plus je ne vois pas d'erreur d'indentation :(
>>> # un émetteur
>>> message["From"] = email_address
File "<stdin>", line 1
message["From"] = email_address
IndentationError: unexpected indent
>>>
>>> # un destinataire
>>> message["To"] = 'spammed327@gmail.com'
File "<stdin>", line 1
message["To"] = 'spammed327@gmail.com'
IndentationError: unexpected indent
>>>
>>> # un émetteur
>>> message["From"] = email_address
File "<stdin>", line 1
message["From"] = email_address
IndentationError: unexpected indent
>>>
>>> # un destinataire
>>> message["To"] = 'spammed327@gmail.com'
File "<stdin>", line 1
message["To"] = 'spammed327@gmail.com'
IndentationError: unexpected indent
>>>
>>> for chaine in myresult:
...
... email_receiver = chaine["Mail"]
...
... Nom = chaine["Nom"]
...
... Prenom = chaine["Prenom"]
...
... Mail = chaine["Mail"]
...
... #print(Mail,Nom,Prenom)
...
>>>
>>> # on crée un e-mail
>>> message = MIMEMultipart("alternative")
File "<stdin>", line 1
message = MIMEMultipart("alternative")
IndentationError: unexpected indent
>>> # on ajoute un sujet
>>> message["Subject"] = "SolareWatt Lodévois"
File "<stdin>", line 1
message["Subject"] = "SolareWatt Lodévois"
IndentationError: unexpected indent
>>> # un émetteur
>>> message["From"] = email_address
File "<stdin>", line 1
message["From"] = email_address
IndentationError: unexpected indent
>>>
>>> # un destinataire
>>> message["To"] = 'spammed327@gmail.com'
File "<stdin>", line 1
message["To"] = 'spammed327@gmail.com'
IndentationError: unexpected indent
>>>
Comme vous pouvez voir, la première partie fonctionne mais ça bloque sur l'indentation après. Pourtant c'est bien indenté pour correspondre à la boucle for
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question