Error occurs running code in terminal "TypeError: cannot unpack non-iterable NoneType object"

Vyom Bhardwaj
def ran_keys(issue1,issue2=None):
    ran_number = random.sample(data.keys(), 1)
    for i in ran_number:
        val1 = data.get(i)
    n3, s3, t3, r3 = val1
    if issue1 == r3:
        return val1
    else:
        if Counter == 1:
            ran_keys(first_issue,second_issue)
        elif Counter == 2:
            ran_keys(first_issue)


def random_mode():
    if Counter == 1:
        vall = ran_keys(first_issue,second_issue)
        name3, s3, t3, r3 = vall
        if r3 == first_issue or second_issue:
            print('Random selected agent available for your issue = \n')
            print('{:<15}  {:<15}  {:<15}  {:<15}'.format('Name', 'Availability', 'Available Since', 'Role'))
            print('{:<15}  {:<15}  {:<15}  {:<15}'.format(name3, s3, t3, r3))
        else:
            print('No agent found for your issue..........\nTry Again..................')
            main1()
    elif Counter == 2:
        vall = ran_keys(first_issue)
        name3, s3, t3, r3 = vall
        if r3 == first_issue:
            print('Random selected agent available for your issue = \n')
            print('{:<15}  {:<15}  {:<15}  {:<15}'.format('Name', 'Availability', 'Available Since', 'Role'))
            print('{:<15}  {:<15}  {:<15}  {:<15}'.format(name3, s3, t3, r3))
        else:
            print('No agent found for your issue..........\nTry Again..................')
            main1()

This code gives me an error when I run it on terminal. The error is :

  File "C:/Users/Acer/Desktop/python_class/project/addCopy.py", line 295, in modes
    random_mode()
  File "C:/Users/Acer/Desktop/python_class/project/addCopy.py", line 264, in random_mode
    name3, s3, t3, r3 = vall
TypeError: cannot unpack non-iterable NoneType object

but when I run it on Python console, it works perfectly fine

Note: The code given above is a part of code so some variables wouldn't be present here.

hack3r_0m

function ran_keys returns val1 if issue1 == r3, but there is no return statement in your else condition, try:

def ran_keys(issue1,issue2=None):
    ran_number = random.sample(data.keys(), 1)
    for i in ran_number:
        val1 = data.get(i)
    n3, s3, t3, r3 = val1
    if issue1 == r3:
        return val1
    else:
        if Counter == 1:
            return ran_keys(first_issue,second_issue)
        elif Counter == 2:
            return ran_keys(first_issue)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error in terminal while running a code

This error occurs when I'm running my code on terminal "TypeError: cannot unpack non-iterable NoneType object"

How to get code to keep running even if error occurs

If an error occurs in code execution, focus on the Visual Studio Code window that the code running

The code is not running in terminal

Syntax error when using decorator and running code selection in terminal (macOS)

Meteor - When running the "Meteor" error occurs

Cycle error occurs when running 'npm start'?

When running the DAML sandbox an error occurs

Python: Running this code from terminal

Error when running HardInfo in terminal?

Why is my VS code terminal not running the code?

Code not running from terminal in vs code

Execute code if condition is met or error occurs

Code converting error occurs using GCC 7.3.0

How to run other code when an error occurs?

Redirect input from code or terminal to running code or terminal?

OpenCV C++ code runs fine in terminal but error in running from eclipse - Ubuntu 12.04

Python code runs fine in pycharm but gives module error while running in terminal

VS Code - Debugger gives module error, but running same command from terminal works

Error in running Haskell code

Issue while running Java code through terminal

Facing problem in java code while running in terminal

How to debug code running from terminal in pycharm

Shortcut for running terminal command in VS code

Trouble running python in VS code python terminal

Running a code on a set of files in mac terminal

Having issues in running python code in Terminal with tkinter

Running python file through VS Code terminal