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
#2
data = '0xffffffff'
int(data, 16)
99 percent of computer problems exists between chair and keyboard.
Reply
#3
Print 'data' before to convert it to integer and use it to calculate the crc and you will see why is that.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
or
data = 0xffffffff
int(hex(data), 16)
99 percent of computer problems exists between chair and keyboard.
Reply
#5
Are you thinging this?
data = 0xffffffff
	data = ReadFile(0, 1024)

	custom_crc = crc.custom_crc32(int(hex(data), 16))
Because, now I get new error:
  • custom_crc = crc.custom_crc32(int(hex(data), 16))
    TypeError: hex() argument can't be converted to hex
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: invalid literal for int() with base 10: omega_elite 5 5,674 Dec-30-2020, 06:11 AM
Last Post: delonbest
  invalid literal for int() with base 10: '# NRECS: 1096\n' Baloch 8 4,452 May-24-2020, 02:08 AM
Last Post: Larz60+
  invalid literal for int() with base 10: '' mrsenorchuck 5 5,321 Apr-29-2020, 05:48 AM
Last Post: markfilan
  ValueError: invalid literal for int() with base 10: '\n' srisrinu 9 5,573 Apr-13-2020, 01:30 PM
Last Post: ibreeden
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,738 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  input-ValueError: invalid literal for int() jacklee26 2 2,509 Feb-21-2020, 01:27 PM
Last Post: ndc85430
  ValueError: invalid literal for int() with base 10: '0.5' emmapaw24 2 3,671 Feb-16-2020, 07:24 PM
Last Post: emmapaw24
  Pi in base 12 problem kevolegend 3 2,111 Sep-22-2019, 05:38 PM
Last Post: kevolegend
  ValueError: invalid literal for int() with base 10: '' Jay123 7 7,214 Aug-05-2019, 02:43 PM
Last Post: Jay123
  ValueError: invalid literal for int() with base 10: '' ivinjjunior 6 9,068 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