• Register
1 vote
145 views

Problem:

For the following code I got some error message like:

ValueError: not enough values to unpack (expected 3, got 2)

The code:

import openpyxl, smtplib, sys



wbs = openpyxl.load_workbook('duesRecords.xlsx')
sheet = wb.get_sheet_by_name('Sheet1')

lastCol = sheet.max_column
latestMonth = sheet.cell(row=1, column=lastCol).value


unpaidMembers = {}
for r in range(2, sheet.max_row + 1):
payments = sheet.cell(row=r, column=lastCol).value
if payment != 'zaplacone':
    name = sheet.cell(row=r, column=2).value
    lastname = sheet.cell(row=r, column=3).value
    email = sheet.cell(row=r, column=4).value
    unpaidMembers[name] = email



smtpObj = smtplib.SMTP_SSL('lansfl.gmail.com', 465)
smtpObj.ehlo()
smtpObj.login('xyz@xyz.com', '1234')



for name, email in unpaidMembers.items()
body = "Subject: %s - przypomnienie o platnosci raty za treningi GIT Parkour. " \
       "\n\nPrzypominamy o uregulowaniu wplaty za uczestnictwo: %s w treningach GIT Parkour w ." \
       "\n\nRecords show  that you have not paid dues for %s. Please make " \
       "this payment as soon as possible."%(latestMonth, name, latestMonth)
print('Sending email to %s...' % email)
sendmailStatus = smtpObj.sendmail('abc@abc.com', email, body)

if sendmailStatus != {}:
    print('There was a problem sending email to %s: %s' % (email,
    sendmailStatus))
smtpObj.quit()

Can anyone help me out to solve this problem?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote

Answer:

The error message

not enough values to unpack (expected 3, got 2)

 means a 2 part tuple, but assign to 3 values.

So, do the followings:

1. Assign the lastname you are reading out here

2. lastname = sheet.cell(row=r, column=3).value
to something; currently the program just forgets it, you could do that two lines after, like so

3. unpaidMembers[name] = lastname, email
(your program will still crash at the same place, because .items() still won't give you 3-tuples but rather something that has this structure: (name, (lastname, email)))

4. Good news is, python can handle this

So, for name, (lastname, email) in unpaidMembers.items():

Hope this should solve your problem.

11 6 4
34,950 points

Related questions

0 votes
1 answer 15 views
15 views
Problem: How to I Solve this: valueerror: not enough values to unpack (expected 2, got 0) HELP! I need help understanding this: valueerror: not enough values to unpack (expected 2, got 0) Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 6 Mashhoodch 13k points
0 votes
1 answer 2 views
2 views
Problem: ValueError: not enough values to unpack (expected 11, got 1).I wrote a script for system automation, but I'm getting the error described in the title.What is the problem?
asked Apr 12 sumaiya simi 23.4k points
1 vote
1 answer 170 views
170 views
Problem: I am getting an error while I am trying to run a python program. Please have a look at it and give me a solution if possible. I am trying to figure the problem but I fail to do so. from sys import argv script, usr_name =argv prompt = '>' ... more than 1 value to unpack” Traceback (most recent call last): script, usr_name =argv ValueError: need more than 1 value to unpack Thanks.
asked Mar 28, 2020 Gavin 15.3k points
0 votes
1 answer 26 views
26 views
Problem: I am a python beginner . I was trying to run this code : def main(): print ( " This program computes the average of two exam scores . ") score1,score2 = input ("Enter two scores separated by a comma:") average = (score1 + score2)/2.0 print ("The ... average ) when I summon the main() I got this ValueError : ValueError: too many values to unpack (expected 2) what is wrong with this code ?
asked Feb 17 Mashhoodch 13k points
0 votes
1 answer 17 views
17 views
Problem: i am getting error: ValueError: need more than 2 values to unpack when i run the unit test now, so 2 failures and one skip now as far as i have read about lambda i: get_error_count(self._error_lookup, i)) line 142 of source is the method for test, err, ... = get_error_count(i) reference Python 3.0 has something a bit like this. Excess values can be bound (as a list) to the last variable:
asked Feb 15 Mashhoodch 13k points
0 votes
1 answer 4 views
4 views
Problem: I am getting the 'too many values to unpack' error. Any idea how I can fix this?
asked Mar 17 ummesalma 27.2k points
0 votes
1 answer 68 views
68 views
Problem: I am learning Python. Recently I got an assignment in which I had to replace some characters of a string with other characters. While searching for the solution on the Internet, I came across the translate() method that can be used to do so. I tried the ... print(string.translate(string ,table)); I do not know why this problem occurs. Can anybody here help me sort out this error? Thanks!
asked Dec 27, 2020 Code Learner 9.5k points
1 vote
1 answer 3 views
3 views
Problem: Any ideas on what I need to do to fix this? python valueerror: too many values to unpack
asked Mar 19 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 44 views
44 views
Problem: I am getting the 'valueerror:too many values to unpack' error. Any idea how I can fix this? Here is my sample program first_names = ['foo', 'bar'] last_names = ['gravy', 'snowman'] fields = { 'first_names': first_names, 'last_name': last_names, } for field, possible_values in fields: # error happens on this line
asked Mar 7, 2020 Gavin 15.3k points
0 votes
1 answer 8 views
8 views
Problem: Can someone help me valueerror: buffer has wrong number of dimensions (expected 1, got 2)?
asked Mar 6 Umar Ahmad 4.1k points