Python loop not running
can anyone help me fix the following code? After the question is asked, and when I reply "yes", the rest of the program doesn't run. No emails are sent.
Note that I've replaced the login data with 'example' just for this question. The actual code has valid login details
Edited the variable from "x" to "answer"
combo = open("combo.txt", "r")
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
count = str(len(combo.readlines( )))
print ("There are " + count + " amount of combos")
answer = input("Would you like to run this program?: ")
for line in combo:
pieces = line.split(":")
email = pieces[0]
password = pieces[1]
if answer == "yes":
msg = MIMEMultipart()
message = "Dear user, your Spotify account has been hackedn" + "Your spotify email is: " + email + ", and your password is: " +password + "n Please change your password ASAP"
passwordEmail = "example"
msg['From'] = "example@gmail.com"
msg['To'] = email
msg['Subject'] = "Spotify Account Hacked"
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'], passwordEmail)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
python loops
|
show 3 more comments
can anyone help me fix the following code? After the question is asked, and when I reply "yes", the rest of the program doesn't run. No emails are sent.
Note that I've replaced the login data with 'example' just for this question. The actual code has valid login details
Edited the variable from "x" to "answer"
combo = open("combo.txt", "r")
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
count = str(len(combo.readlines( )))
print ("There are " + count + " amount of combos")
answer = input("Would you like to run this program?: ")
for line in combo:
pieces = line.split(":")
email = pieces[0]
password = pieces[1]
if answer == "yes":
msg = MIMEMultipart()
message = "Dear user, your Spotify account has been hackedn" + "Your spotify email is: " + email + ", and your password is: " +password + "n Please change your password ASAP"
passwordEmail = "example"
msg['From'] = "example@gmail.com"
msg['To'] = email
msg['Subject'] = "Spotify Account Hacked"
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'], passwordEmail)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
python loops
6
if x == "yes":
- you've not definedx
anywhere?
– Robin Zigmond
Nov 14 '18 at 22:07
2
I cant believe Ive made such a silly mistake! thanks for pointing it out!
– ScriptKiddie
Nov 14 '18 at 22:08
Ive changed it to answer, but the same result occurs. no email is sent
– ScriptKiddie
Nov 14 '18 at 22:10
1
Your mistake should have thrown an error...what IDE are you using?
– roganjosh
Nov 14 '18 at 22:10
1
combo.readlines()
will read to the end of the file. Sayingfor line in combo
finds no lines left to iterate.
– Peter Wood
Nov 14 '18 at 22:18
|
show 3 more comments
can anyone help me fix the following code? After the question is asked, and when I reply "yes", the rest of the program doesn't run. No emails are sent.
Note that I've replaced the login data with 'example' just for this question. The actual code has valid login details
Edited the variable from "x" to "answer"
combo = open("combo.txt", "r")
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
count = str(len(combo.readlines( )))
print ("There are " + count + " amount of combos")
answer = input("Would you like to run this program?: ")
for line in combo:
pieces = line.split(":")
email = pieces[0]
password = pieces[1]
if answer == "yes":
msg = MIMEMultipart()
message = "Dear user, your Spotify account has been hackedn" + "Your spotify email is: " + email + ", and your password is: " +password + "n Please change your password ASAP"
passwordEmail = "example"
msg['From'] = "example@gmail.com"
msg['To'] = email
msg['Subject'] = "Spotify Account Hacked"
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'], passwordEmail)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
python loops
can anyone help me fix the following code? After the question is asked, and when I reply "yes", the rest of the program doesn't run. No emails are sent.
Note that I've replaced the login data with 'example' just for this question. The actual code has valid login details
Edited the variable from "x" to "answer"
combo = open("combo.txt", "r")
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
count = str(len(combo.readlines( )))
print ("There are " + count + " amount of combos")
answer = input("Would you like to run this program?: ")
for line in combo:
pieces = line.split(":")
email = pieces[0]
password = pieces[1]
if answer == "yes":
msg = MIMEMultipart()
message = "Dear user, your Spotify account has been hackedn" + "Your spotify email is: " + email + ", and your password is: " +password + "n Please change your password ASAP"
passwordEmail = "example"
msg['From'] = "example@gmail.com"
msg['To'] = email
msg['Subject'] = "Spotify Account Hacked"
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'], passwordEmail)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
python loops
python loops
edited Nov 14 '18 at 22:17
ScriptKiddie
asked Nov 14 '18 at 22:05
ScriptKiddieScriptKiddie
22
22
6
if x == "yes":
- you've not definedx
anywhere?
– Robin Zigmond
Nov 14 '18 at 22:07
2
I cant believe Ive made such a silly mistake! thanks for pointing it out!
– ScriptKiddie
Nov 14 '18 at 22:08
Ive changed it to answer, but the same result occurs. no email is sent
– ScriptKiddie
Nov 14 '18 at 22:10
1
Your mistake should have thrown an error...what IDE are you using?
– roganjosh
Nov 14 '18 at 22:10
1
combo.readlines()
will read to the end of the file. Sayingfor line in combo
finds no lines left to iterate.
– Peter Wood
Nov 14 '18 at 22:18
|
show 3 more comments
6
if x == "yes":
- you've not definedx
anywhere?
– Robin Zigmond
Nov 14 '18 at 22:07
2
I cant believe Ive made such a silly mistake! thanks for pointing it out!
– ScriptKiddie
Nov 14 '18 at 22:08
Ive changed it to answer, but the same result occurs. no email is sent
– ScriptKiddie
Nov 14 '18 at 22:10
1
Your mistake should have thrown an error...what IDE are you using?
– roganjosh
Nov 14 '18 at 22:10
1
combo.readlines()
will read to the end of the file. Sayingfor line in combo
finds no lines left to iterate.
– Peter Wood
Nov 14 '18 at 22:18
6
6
if x == "yes":
- you've not defined x
anywhere?– Robin Zigmond
Nov 14 '18 at 22:07
if x == "yes":
- you've not defined x
anywhere?– Robin Zigmond
Nov 14 '18 at 22:07
2
2
I cant believe Ive made such a silly mistake! thanks for pointing it out!
– ScriptKiddie
Nov 14 '18 at 22:08
I cant believe Ive made such a silly mistake! thanks for pointing it out!
– ScriptKiddie
Nov 14 '18 at 22:08
Ive changed it to answer, but the same result occurs. no email is sent
– ScriptKiddie
Nov 14 '18 at 22:10
Ive changed it to answer, but the same result occurs. no email is sent
– ScriptKiddie
Nov 14 '18 at 22:10
1
1
Your mistake should have thrown an error...what IDE are you using?
– roganjosh
Nov 14 '18 at 22:10
Your mistake should have thrown an error...what IDE are you using?
– roganjosh
Nov 14 '18 at 22:10
1
1
combo.readlines()
will read to the end of the file. Saying for line in combo
finds no lines left to iterate.– Peter Wood
Nov 14 '18 at 22:18
combo.readlines()
will read to the end of the file. Saying for line in combo
finds no lines left to iterate.– Peter Wood
Nov 14 '18 at 22:18
|
show 3 more comments
1 Answer
1
active
oldest
votes
As pointed out by @Robin Zigmond, you haven't declared x
yet.
A useful thing whilst debugging code that is evidently not functioning, I always find, is to use print statements to check what I believe to be true. In this case, you could check immediately before the if
statement by doing print(x)
, to see what the value was - that would have highlighted that the variable didn't exist.
1
Can you explain why they didn't get an error for this?
– roganjosh
Nov 14 '18 at 22:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309429%2fpython-loop-not-running%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As pointed out by @Robin Zigmond, you haven't declared x
yet.
A useful thing whilst debugging code that is evidently not functioning, I always find, is to use print statements to check what I believe to be true. In this case, you could check immediately before the if
statement by doing print(x)
, to see what the value was - that would have highlighted that the variable didn't exist.
1
Can you explain why they didn't get an error for this?
– roganjosh
Nov 14 '18 at 22:11
add a comment |
As pointed out by @Robin Zigmond, you haven't declared x
yet.
A useful thing whilst debugging code that is evidently not functioning, I always find, is to use print statements to check what I believe to be true. In this case, you could check immediately before the if
statement by doing print(x)
, to see what the value was - that would have highlighted that the variable didn't exist.
1
Can you explain why they didn't get an error for this?
– roganjosh
Nov 14 '18 at 22:11
add a comment |
As pointed out by @Robin Zigmond, you haven't declared x
yet.
A useful thing whilst debugging code that is evidently not functioning, I always find, is to use print statements to check what I believe to be true. In this case, you could check immediately before the if
statement by doing print(x)
, to see what the value was - that would have highlighted that the variable didn't exist.
As pointed out by @Robin Zigmond, you haven't declared x
yet.
A useful thing whilst debugging code that is evidently not functioning, I always find, is to use print statements to check what I believe to be true. In this case, you could check immediately before the if
statement by doing print(x)
, to see what the value was - that would have highlighted that the variable didn't exist.
answered Nov 14 '18 at 22:10
HenryHenry
1,222618
1,222618
1
Can you explain why they didn't get an error for this?
– roganjosh
Nov 14 '18 at 22:11
add a comment |
1
Can you explain why they didn't get an error for this?
– roganjosh
Nov 14 '18 at 22:11
1
1
Can you explain why they didn't get an error for this?
– roganjosh
Nov 14 '18 at 22:11
Can you explain why they didn't get an error for this?
– roganjosh
Nov 14 '18 at 22:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309429%2fpython-loop-not-running%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
if x == "yes":
- you've not definedx
anywhere?– Robin Zigmond
Nov 14 '18 at 22:07
2
I cant believe Ive made such a silly mistake! thanks for pointing it out!
– ScriptKiddie
Nov 14 '18 at 22:08
Ive changed it to answer, but the same result occurs. no email is sent
– ScriptKiddie
Nov 14 '18 at 22:10
1
Your mistake should have thrown an error...what IDE are you using?
– roganjosh
Nov 14 '18 at 22:10
1
combo.readlines()
will read to the end of the file. Sayingfor line in combo
finds no lines left to iterate.– Peter Wood
Nov 14 '18 at 22:18