Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ValueError: embedded null character" when using open()

Tags:

python

I am taking python at my college and I am stuck with my current assignment. We are supposed to take 2 files and compare them. I am simply trying to open the files so I can use them but I keep getting the error "ValueError: embedded null character"

file1 = input("Enter the name of the first file: ")
file1_open = open(file1)
file1_content = file1_open.read()

What does this error mean?

like image 493
Erica Avatar asked Nov 28 '15 23:11

Erica


People also ask

What is an embedded null character?

Description. The Embedding NULL Bytes/characters technique exploits applications that don't properly handle postfix NULL terminators. This technique can be used to perform other attacks such as directory browsing, path traversal, SQL injection, execution of arbitrary code, and others.

How do I remove a null character from a string in Python?

Solution 1temp = temp. Replace("\0", string. Empty); will remove the null characters.

WHAT IS null character in Python?

null is often defined to be 0 in those languages, but null in Python is different. Python uses the keyword None to define null objects and variables. While None does serve some of the same purposes as null in other languages, it's another beast entirely.


1 Answers

It seems that you have problems with characters "\" and "/". If you use them in input - try to change one to another...

like image 186
Алексей Семенихин Avatar answered Oct 14 '22 14:10

Алексей Семенихин