keyerror while using smtp in python 2.7





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















for row in csv_reader:
username = row ["Username"]
pwd = row ["Password"]
email = row["Username"]
grades = row["Grades"]
comments = row["Comments"]


**my error is: username = row ["Username"]



KeyError: 'Username'**










share|improve this question

























  • can you share the output of print csv_reader ? Might be the result is missing the following keys

    – Anurag Choudhary
    Nov 25 '18 at 8:41











  • Enter your email: Enter Password: upload excel file upload text format for sending mail Opening SMTP session Traceback (most recent call last): File "Emailcode.py", line 76, in <module> username = row['username'] KeyError: 'username'

    – satwik
    Nov 25 '18 at 8:45













  • @satwik try adding the rest of this code into your question with an edit as the information presented here doesn't give enough to find the source of the issue. It only shows us that in the resultant dictionary there is no key corresponding to Username

    – Sven Harris
    Nov 25 '18 at 8:49


















1















for row in csv_reader:
username = row ["Username"]
pwd = row ["Password"]
email = row["Username"]
grades = row["Grades"]
comments = row["Comments"]


**my error is: username = row ["Username"]



KeyError: 'Username'**










share|improve this question

























  • can you share the output of print csv_reader ? Might be the result is missing the following keys

    – Anurag Choudhary
    Nov 25 '18 at 8:41











  • Enter your email: Enter Password: upload excel file upload text format for sending mail Opening SMTP session Traceback (most recent call last): File "Emailcode.py", line 76, in <module> username = row['username'] KeyError: 'username'

    – satwik
    Nov 25 '18 at 8:45













  • @satwik try adding the rest of this code into your question with an edit as the information presented here doesn't give enough to find the source of the issue. It only shows us that in the resultant dictionary there is no key corresponding to Username

    – Sven Harris
    Nov 25 '18 at 8:49














1












1








1








for row in csv_reader:
username = row ["Username"]
pwd = row ["Password"]
email = row["Username"]
grades = row["Grades"]
comments = row["Comments"]


**my error is: username = row ["Username"]



KeyError: 'Username'**










share|improve this question
















for row in csv_reader:
username = row ["Username"]
pwd = row ["Password"]
email = row["Username"]
grades = row["Grades"]
comments = row["Comments"]


**my error is: username = row ["Username"]



KeyError: 'Username'**







python python-2.7 dictionary keyerror






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 15:34









Zaytsev Dmitry

6912620




6912620










asked Nov 25 '18 at 8:39









satwik satwik

113




113













  • can you share the output of print csv_reader ? Might be the result is missing the following keys

    – Anurag Choudhary
    Nov 25 '18 at 8:41











  • Enter your email: Enter Password: upload excel file upload text format for sending mail Opening SMTP session Traceback (most recent call last): File "Emailcode.py", line 76, in <module> username = row['username'] KeyError: 'username'

    – satwik
    Nov 25 '18 at 8:45













  • @satwik try adding the rest of this code into your question with an edit as the information presented here doesn't give enough to find the source of the issue. It only shows us that in the resultant dictionary there is no key corresponding to Username

    – Sven Harris
    Nov 25 '18 at 8:49



















  • can you share the output of print csv_reader ? Might be the result is missing the following keys

    – Anurag Choudhary
    Nov 25 '18 at 8:41











  • Enter your email: Enter Password: upload excel file upload text format for sending mail Opening SMTP session Traceback (most recent call last): File "Emailcode.py", line 76, in <module> username = row['username'] KeyError: 'username'

    – satwik
    Nov 25 '18 at 8:45













  • @satwik try adding the rest of this code into your question with an edit as the information presented here doesn't give enough to find the source of the issue. It only shows us that in the resultant dictionary there is no key corresponding to Username

    – Sven Harris
    Nov 25 '18 at 8:49

















can you share the output of print csv_reader ? Might be the result is missing the following keys

– Anurag Choudhary
Nov 25 '18 at 8:41





can you share the output of print csv_reader ? Might be the result is missing the following keys

– Anurag Choudhary
Nov 25 '18 at 8:41













Enter your email: Enter Password: upload excel file upload text format for sending mail Opening SMTP session Traceback (most recent call last): File "Emailcode.py", line 76, in <module> username = row['username'] KeyError: 'username'

– satwik
Nov 25 '18 at 8:45







Enter your email: Enter Password: upload excel file upload text format for sending mail Opening SMTP session Traceback (most recent call last): File "Emailcode.py", line 76, in <module> username = row['username'] KeyError: 'username'

– satwik
Nov 25 '18 at 8:45















@satwik try adding the rest of this code into your question with an edit as the information presented here doesn't give enough to find the source of the issue. It only shows us that in the resultant dictionary there is no key corresponding to Username

– Sven Harris
Nov 25 '18 at 8:49





@satwik try adding the rest of this code into your question with an edit as the information presented here doesn't give enough to find the source of the issue. It only shows us that in the resultant dictionary there is no key corresponding to Username

– Sven Harris
Nov 25 '18 at 8:49












2 Answers
2






active

oldest

votes


















0














I think probably value named row does not contain Username key.
You can check all the key via print(row) or print(csv_reader).



Make sure csv_reader is a list that contains dictionaries and Username key.
It looks like this:



csv_reader = [{"Username": "McCree", "Password": "Secret", "Grades": "100" ...}]





share|improve this answer































    0














    let suppose i have a csv file which contain the data as below:



    username,password,email



    John Smith,Pass!12,abc@email.com



    now i can read this csv file in following ways: the first one is with csv.reader(), and the other one is with csv.DictReader().





    • csv.reader() :



      import csv

      with open('filename') as csv_file:
      csv_reader = csv.reader(csv_file, delimiter=',')
      for row in csv_reader:
      #now we assign the username
      #username = row['usename']---this will give an error here
      username = row[0] #this will assign the value at index 0 of row to username



    as row is a list we have to access the value by there index.





    • csv.DictReader()



          import csv
      with open('file_name', mode='r') as csv_file:
      csv_reader = csv.DictReader(csv_file)
      for row in csv_reader:
      #now we assign the username
      username = row.get('username')



    as the csv.DictReader() function convert csv file data in dictionary. so, we have to fetch a particular value with it's key:-- as in example we are doing this with row.get('username').






    share|improve this answer
























      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
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465893%2fkeyerror-while-using-smtp-in-python-2-7%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      I think probably value named row does not contain Username key.
      You can check all the key via print(row) or print(csv_reader).



      Make sure csv_reader is a list that contains dictionaries and Username key.
      It looks like this:



      csv_reader = [{"Username": "McCree", "Password": "Secret", "Grades": "100" ...}]





      share|improve this answer




























        0














        I think probably value named row does not contain Username key.
        You can check all the key via print(row) or print(csv_reader).



        Make sure csv_reader is a list that contains dictionaries and Username key.
        It looks like this:



        csv_reader = [{"Username": "McCree", "Password": "Secret", "Grades": "100" ...}]





        share|improve this answer


























          0












          0








          0







          I think probably value named row does not contain Username key.
          You can check all the key via print(row) or print(csv_reader).



          Make sure csv_reader is a list that contains dictionaries and Username key.
          It looks like this:



          csv_reader = [{"Username": "McCree", "Password": "Secret", "Grades": "100" ...}]





          share|improve this answer













          I think probably value named row does not contain Username key.
          You can check all the key via print(row) or print(csv_reader).



          Make sure csv_reader is a list that contains dictionaries and Username key.
          It looks like this:



          csv_reader = [{"Username": "McCree", "Password": "Secret", "Grades": "100" ...}]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 11:12







          user7121223
































              0














              let suppose i have a csv file which contain the data as below:



              username,password,email



              John Smith,Pass!12,abc@email.com



              now i can read this csv file in following ways: the first one is with csv.reader(), and the other one is with csv.DictReader().





              • csv.reader() :



                import csv

                with open('filename') as csv_file:
                csv_reader = csv.reader(csv_file, delimiter=',')
                for row in csv_reader:
                #now we assign the username
                #username = row['usename']---this will give an error here
                username = row[0] #this will assign the value at index 0 of row to username



              as row is a list we have to access the value by there index.





              • csv.DictReader()



                    import csv
                with open('file_name', mode='r') as csv_file:
                csv_reader = csv.DictReader(csv_file)
                for row in csv_reader:
                #now we assign the username
                username = row.get('username')



              as the csv.DictReader() function convert csv file data in dictionary. so, we have to fetch a particular value with it's key:-- as in example we are doing this with row.get('username').






              share|improve this answer




























                0














                let suppose i have a csv file which contain the data as below:



                username,password,email



                John Smith,Pass!12,abc@email.com



                now i can read this csv file in following ways: the first one is with csv.reader(), and the other one is with csv.DictReader().





                • csv.reader() :



                  import csv

                  with open('filename') as csv_file:
                  csv_reader = csv.reader(csv_file, delimiter=',')
                  for row in csv_reader:
                  #now we assign the username
                  #username = row['usename']---this will give an error here
                  username = row[0] #this will assign the value at index 0 of row to username



                as row is a list we have to access the value by there index.





                • csv.DictReader()



                      import csv
                  with open('file_name', mode='r') as csv_file:
                  csv_reader = csv.DictReader(csv_file)
                  for row in csv_reader:
                  #now we assign the username
                  username = row.get('username')



                as the csv.DictReader() function convert csv file data in dictionary. so, we have to fetch a particular value with it's key:-- as in example we are doing this with row.get('username').






                share|improve this answer


























                  0












                  0








                  0







                  let suppose i have a csv file which contain the data as below:



                  username,password,email



                  John Smith,Pass!12,abc@email.com



                  now i can read this csv file in following ways: the first one is with csv.reader(), and the other one is with csv.DictReader().





                  • csv.reader() :



                    import csv

                    with open('filename') as csv_file:
                    csv_reader = csv.reader(csv_file, delimiter=',')
                    for row in csv_reader:
                    #now we assign the username
                    #username = row['usename']---this will give an error here
                    username = row[0] #this will assign the value at index 0 of row to username



                  as row is a list we have to access the value by there index.





                  • csv.DictReader()



                        import csv
                    with open('file_name', mode='r') as csv_file:
                    csv_reader = csv.DictReader(csv_file)
                    for row in csv_reader:
                    #now we assign the username
                    username = row.get('username')



                  as the csv.DictReader() function convert csv file data in dictionary. so, we have to fetch a particular value with it's key:-- as in example we are doing this with row.get('username').






                  share|improve this answer













                  let suppose i have a csv file which contain the data as below:



                  username,password,email



                  John Smith,Pass!12,abc@email.com



                  now i can read this csv file in following ways: the first one is with csv.reader(), and the other one is with csv.DictReader().





                  • csv.reader() :



                    import csv

                    with open('filename') as csv_file:
                    csv_reader = csv.reader(csv_file, delimiter=',')
                    for row in csv_reader:
                    #now we assign the username
                    #username = row['usename']---this will give an error here
                    username = row[0] #this will assign the value at index 0 of row to username



                  as row is a list we have to access the value by there index.





                  • csv.DictReader()



                        import csv
                    with open('file_name', mode='r') as csv_file:
                    csv_reader = csv.DictReader(csv_file)
                    for row in csv_reader:
                    #now we assign the username
                    username = row.get('username')



                  as the csv.DictReader() function convert csv file data in dictionary. so, we have to fetch a particular value with it's key:-- as in example we are doing this with row.get('username').







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 25 '18 at 11:53









                  Abhishek-SainiAbhishek-Saini

                  9112




                  9112






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465893%2fkeyerror-while-using-smtp-in-python-2-7%23new-answer', 'question_page');
                      }
                      );

                      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







                      這個網誌中的熱門文章

                      Academy of Television Arts & Sciences

                      L'Équipe

                      1995 France bombings