[python] 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. My code below is the relevant portion of the script. What is the problem?

import csv
import os

DIR = "C:/Users/Administrator/Desktop/key_list.csv"

def Customer_List(csv):
    customer = open(DIR)
        for line in customer:
            row = []
            (row['MEM_ID'],
             row['MEM_SQ'],
             row['X_AUTH_USER'],
             row['X_AUTH_KEY'],
             row['X_STORAGE_URL'],
             row['ACCESSKEY'],
             row['ACCESSKEYID'],
             row['ACCESSKEY1'],
             row['ACCESSKEYID1'],
             row['ACCESSKEY2'],
             row['ACCESSKEYID2'])=line.split()
            if csv == row['MEM_ID']:
                customer.close()
                return(row)
            else:
                print ("Not search for ID")
                return([])

id_input = input("Please input the Customer ID(Email): ")
result = Customer_List(id_input)

if result:
    print ("iD:    " + id['MEM_ID']

This question is related to python csv

The answer is


The error message is fairly self-explanatory

(a,b,c,d,e) = line.split()

expects line.split() to yield 5 elements, but in your case, it is only yielding 1 element. This could be because the data is not in the format you expect, a rogue malformed line, or maybe an empty line - there's no way to know.

To see what line is causing the issue, you could add some debug statements like this:

if len(line.split()) != 11:
    print line

As Martin suggests, you might also be splitting on the wrong delimiter.


Looks like something is wrong with your data, it isn't in the format you are expecting. It could be a new line character or a blank space in the data that is tinkering with your code.