我收到此错误,我不知道该怎么办:ValueError:chr()arg不在范围内(0x110000)

时间:2020-04-04 19:50:49

标签: python

我正在开发一个程序,用于将二进制文件的内容转换为可读的ACII。这是我的代码:

import struct
import base64
import codecs
import re
print("************Welcome to binary dumper and binary to ASCII decoder************")
print("Please only choose BINARY CONTENT files because otherwise an error will ocurr")
filename_ext = input("Enter filname to be dumped and decoded: ")
print("\n")
filename = input("Please enter the filename WITHOUT the extention: ")
print("\n")
print("Printing binary data...")
print("\n")
f = open(filename_ext, 'rb')
content = f.read()
f.close()
print(content)
contenttoconvert = input("Please copy the content that was output before and paste it here: ")
resubedcontent = re.sub("b|'", "", contenttoconvert)

padding = "=========".encode('utf-8')

base64_file_bytes = str(content).encode('utf-8')

a_binary_string = int(str(resubedcontent), 2)

binary_values = str(a_binary_string).split()
#Split string on whitespace

ascii_string = ""
for binary_value in binary_values:
    an_integer = int(binary_value)
#Convert to base 2 decimal integer


    ascii_character = chr(an_integer)
#Convert to ASCII character


    ascii_string += ascii_character
#Append character to `ascii_string`


print(ascii_string)

with open("output_" + filename, 'wb')as output:
    print("\n")
    print("Outputing file...")
    print("\n")
    decoded_file_data = base64.decodebytes(base64_file_bytes + padding)
    output.write(codecs.encode(decoded_file_data, 'hex_codec'))

文件的内容是这样的:01010000010101010110101010001000001.希望我清楚我的解释,因为我不善于问技术问题。问题是有时我会理解该错误,但不知道如何解决,但在这种情况下,我根本不了解它。

0 个答案:

没有答案