TypeError: coercing to Unicode: need string or buffer, NoneType found in Python
Currently I write a function for a program and one component is to find out if separate variables are used in the python file. Like this:
def SINGLE_CHAR_VAR(python_filename): file = open(python_filename) lines =  SINGLE_CHAR_VAR =  for line in file: stripped = line.strip('\n\r') lines.append(stripped) from utils import vars_indents variable_list = (vars_indents(python_filename)) for i in range(1, len(variable_list)): if len(variable_list[i]) == 1: SINGLE_CHAR_VAR.append(['SINGLE_CHAR_VAR', i, variable_list[i], variable_list[i], lines[i]]) return SINGLE_CHAR_VAR
When I used the function on its own - the function works correctly. However, when I call the program as a whole - I get the following error message TypeError: coercing to Unicode: need string or buffer, NoneType found:
Traceback (most recent call last): File "<web session>", line 1, in <module> File "lint_2.py", line 141, in lint sorted_error_list = sorted_list(list_of_file_errors) File "lint_2.py", line 84, in sorted_list error_list = total_error_list(python_filename) File "lint_2.py", line 65, in total_error_list single_char_var_list = SINGLE_CHAR_VAR(python_filename) File "lint_2.py", line 33, in SINGLE_CHAR_VAR file = open(python_filename) TypeError: coercing to Unicode: need string or buffer, NoneType found
I have absolutely no idea where I am wrong - any help would be very, very, very welcome !!!
Thanks for any suggestions.
pablo C Sep 17 2021
Try to write it like this:
ssh.exec_command() stdin.flush() stdin.channel.shutdown_write()
It should work.
Dhiraj Goplani Sep 17 2021
None, you cannot tell from the code you posted. The feedback you provided assumes the value comes from a function
sorted_list(), I suggest you start looking for clues there:
File "lint_2.py", line 84, in sorted_list error_list = total_error_list(python_filename)
However, this is just speculation; you will have to trace through all the code in this trace to see exactly where it is being
Noneinstalled the first time.