Questions tagged [binascii]

50 questions
16
votes
2 answers

Python: How to catch this Error (can't source error name) - binascii.Error

I'm using the base64 module for the b64decode() function, however certain strings of text throw this error: 'binascii.Error: Incorrect Padding'. I understand that this is because the strings are not of length multiple of 4, a requirement of base64…
Jckxxlaw
  • 391
  • 1
  • 4
  • 12
5
votes
2 answers

Odd-length string error with binascii.unhexlify

I'm trying to convert back and forth an ASCII string to its binary representation as follows. s=chr(0)*15 + chr(0x01) bst = bin(int(binascii.hexlify(s), 16)) n = int(bst, 2) binascii.unhexlify('%x' % n) However, I get the following error at the…
SpiderRico
  • 1,890
  • 8
  • 28
  • 48
4
votes
1 answer

Sending bytes in a string to Redis in order to using it as parameter for Celery's task

I want to send bytes in a string to Celery's task using Redis as broker, but I'm receiving error shown below: [2017-06-17 21:27:13,826] ERROR in app: Exception on /endpoint_method [POST] Traceback (most recent call last): File…
dawlib
  • 237
  • 2
  • 13
3
votes
2 answers

CRC32 In Python (vs CRC32b)

I am trying to generate some crc32 hashes, but it seems like zlib and binascii use the crc32b algorithm even though their respective functions are simply zlib.crc32 and binascii.crc32. Are there any other python resources for hash generation that I…
Kelley Brady
  • 348
  • 2
  • 10
3
votes
1 answer

Hexlify input using Binascii

I am trying to hexlify input from user but I get the following error: TypeError: a bytes-like object is required, not 'str' If I use b before string then it works but how can I do it with input? Here is the code: import binascii as bs text =…
Nouman
  • 6,947
  • 7
  • 32
  • 60
3
votes
1 answer

json.loads and Redis in python 3.5

I created a JSON object with json.dumps() and RPUSH(ed) it in a redis list. When getting back the JSON with LRANGE ( redis.lrange() ) I receive a binary string b'{"si":"00:ff" ... So json.loads() raises an error: *** TypeError: the JSON object…
Guido
  • 634
  • 1
  • 8
  • 19
2
votes
1 answer

Writing hex string into a binary file

I am trying to write an hex string into a file using python 2.7 so that when opened with HxD I can retrieve the same hex values. The following code works fine on multiple input strings, but when the string contains '0A' the writing is not working…
2
votes
1 answer

Differences of the ord() function between Python 2.7 and 3.9

Good morning people! I've been trying to convert this code written in Python 2 to Python 3.It's a simple function to encrypt strings using XOR. What I have so far: import binascii def encrypt(content: str, key: str) -> str: key_id = 0 xored…
2
votes
1 answer

inverse of a detailed transformation

I am working with a piece of code that transforms for example this list of 256 integers: a = [50, 177, 75, 135, 123, 30, 218, 164, 42, 29, 144, 38, 241, 154, 172, 142, 27, 1, 109, 198, 200, 230, 88, 235, 4, 86, 34, 112, 50, 116, 10, 156, 136, 48,…
cardamom
  • 6,873
  • 11
  • 48
  • 102
2
votes
2 answers

Ruby pack('H*') equivalent in Python

I'm having a hard time figuring out why outputs aren't the same. Notice that the difference is very tiny if you compare both OUT's. What I'm trying to achieve is have the same output in Python to the one in…
roks0n
  • 74
  • 1
  • 6
2
votes
1 answer

Zlib and binascii don't build with Python3.6

I've been trying to build Python3.6.1 from source code on Ubuntu 14.04. The sequence of commands is as recommended by README: ./configure make make test The latter crashes because it cannot import binascii. In its output there is a…
Synedraacus
  • 975
  • 1
  • 8
  • 21
2
votes
3 answers

How to convert huge binary data into ASCII format?

I want to read a file which contains huge binary data. I want to convert this binary data into ASCII format. At the time of start, I want to read 2 bytes which indicates size of message, message is ahead of size. After reading this whole message,…
ketan
  • 2,732
  • 11
  • 34
  • 80
2
votes
1 answer

Converting binary data to hex in python properly

I'm working on a program that uses a BMP and a separate file for the transparency layer. I need to convert them into a PNG from that so I'm using PIL in python to do so. However, I need the data from the transparency file in hex so it can be added…
Yascob
  • 21
  • 2
2
votes
1 answer

Python binascii.unhexlify TypeError: Odd-length string with non-printable character

I'm trying to use Python to perform binary xor operation on two strings, returning a string of ascii characters. I use binascii python module. I have the following issue with the last conversion binaryString -> ASCII characters. I have a following…
agienka
  • 396
  • 1
  • 2
  • 11
2
votes
1 answer

Compiling Python3.5 on RedHat 6.4 - missing tkinter

Did any of you encountered an issue with missing tkInter when trying to compile the new Python from source on redhat 6? "The necessary bits to build these optional modules were not found: _tkinter To find the necessary bits, look in setup.py in…
Marcin P.
  • 21
  • 2
1
2 3 4