Python Forum
Problem with "invalid literal for int() with base 10: ''
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with "invalid literal for int() with base 10: ''
#1
Hello friends.

I try calculate CRC32 from my binary file. But Anythink is wrong.

Here is function to read and print block of bin file. It is working very fine.
def ReadFile(offset, blok):
	i = -15
	filename = "EMPTY.bin"
	blocksize = blok
	
	opts,args = getopt.getopt(sys.argv[1:],'f:b:')
	
	for o,a in opts:
		if o == '-f':
			filename = a
		if o == '-b':
			blocksize = a
	
	with open(filename,"rb") as f:
		f.seek(offset, 1)
		block = f.read(blocksize)
		str = ""
		odsaz = ""

		for ch in block:
			str += hex(ord(ch))[2:].zfill(2)+" "
			if (i % 16 == 0):
				odsaz += hex(i)[2:].zfill(8) + ": " + str + "\n"
				str = ""
			i = i + 1
		#vypise do konzole vygenerovany log
		print odsaz
		return block
And I have finction to calculate CRC32:
custom_crc_table = {}

def int_to_bytes(i):
    return [(i >> 24) & 0xFF, (i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF]


def generate_crc32_table(_poly):

    global custom_crc_table

    for i in range(256):
        c = i << 24

        for j in range(8):
            c = (c << 1) ^ _poly if (c & 0x80000000) else c << 1

        custom_crc_table[i] = c & 0xffffffff


def custom_crc32(buf):

    global custom_crc_table
    crc = 0xffffffff

    for integer in buf:
        b = int_to_bytes(integer)

        for byte in b:
            crc = ((crc << 8) & 0xffffffff) ^ custom_crc_table[(crc >> 24) ^ byte]

    return crc
And problem is this. I have this main:
crc.generate_crc32_table(poly)
data = ReadFile(0, 1024)
custom_crc = crc.custom_crc32(int(data))
And I get error:
  • File "C:\Users\jirka\Desktop\CRC32\test.py", line 63, in <module>
    custom_crc = crc.custom_crc32(int(data))
    ValueError: invalid literal for int() with base 10: ''

Can you help me, how to solve the problem? Thank you.
Reply


Messages In This Thread
Problem with "invalid literal for int() with base 10: '' - by jirkaj4 - Jan-23-2018, 06:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: invalid literal for int() with base 10: omega_elite 5 5,857 Dec-30-2020, 06:11 AM
Last Post: delonbest
  invalid literal for int() with base 10: '# NRECS: 1096\n' Baloch 8 4,592 May-24-2020, 02:08 AM
Last Post: Larz60+
  invalid literal for int() with base 10: '' mrsenorchuck 5 5,562 Apr-29-2020, 05:48 AM
Last Post: markfilan
  ValueError: invalid literal for int() with base 10: '\n' srisrinu 9 5,844 Apr-13-2020, 01:30 PM
Last Post: ibreeden
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,918 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  input-ValueError: invalid literal for int() jacklee26 2 2,582 Feb-21-2020, 01:27 PM
Last Post: ndc85430
  ValueError: invalid literal for int() with base 10: '0.5' emmapaw24 2 3,774 Feb-16-2020, 07:24 PM
Last Post: emmapaw24
  Pi in base 12 problem kevolegend 3 2,186 Sep-22-2019, 05:38 PM
Last Post: kevolegend
  ValueError: invalid literal for int() with base 10: '' Jay123 7 7,358 Aug-05-2019, 02:43 PM
Last Post: Jay123
  ValueError: invalid literal for int() with base 10: '' ivinjjunior 6 9,196 Apr-20-2019, 05:37 PM
Last Post: keames

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020