decode

bytes.decode() in Python2 and Python3

bytes.decode() in Python2 and Python3 Question: In the source code of sqlalchemy I see following val = cursor.fetchone()[0] if util.py3k and isinstance(val, bytes): val = val.decode() Why we do decode only for Python3 and doesn’t do it for Python2? Asked By: Rudziankoŭ || Source Answers: You can check out a detail documentation of string encoding …

Total answers: 2

python encoding chinese to special character

python encoding chinese to special character Question: I have scrape/curl request to get html from other site, that have chinese language but some text result is weird, it showing like this: °¢Àï°Í°ÍΪÄúÌṩÁË×ÔÁµÕß¹¤³§Ö±ÏúÆ·ÅƵç×Ó±í ÖÇÄÜʱÉг±Á÷ŮʿÊÖ»·ÊÖÁ´Ê×Êαí´øµÈ²úÆ·£¬ÕâÀïÔƼ¯ÁËÖÚ¶àµÄ¹©Ó¦ÉÌ£¬²É¹ºÉÌ£¬ÖÆÔìÉÌ¡£ÓûÁ˽â¸ü¶à×ÔÁµÕß¹¤³§Ö±ÏúÆ·ÅƵç×Ó±í ÖÇÄÜʱÉг±Á÷ŮʿÊÖ»·ÊÖÁ´Ê×Êαí´øÐÅÏ¢£¬Çë·ÃÎÊ°¢Àï°Í°ÍÅú·¢Íø£¡ that should be in chinese language, and this is my code: str(result.decode(‘ISO-8859-1′)) If without decode ‘ISO-8859-1’ (only return result variable) it …

Total answers: 4

\x to x with python

\x to x with python Question: I have a string like this: ‘\xac\x85’ and I want to encode these string like this another: ‘xacx85’ I tried a lot of things like encode tu utf-8, replace \x, etc. But when I print the result it always is with \x. Any idea? Asked By: XBoss || Source …

Total answers: 2

Display hex data from serial port in print function

Display hex data from serial port in print function Question: I receive data from serial port. It is not ASCII data (like from putty), but hex data from modbus rtu line (for example there is 0103AABBCCDD816E data on the line, where 01 is one byte in raw hex, 03 is another byte in raw hex… …

Total answers: 2

Decoding an image with Stegano Module

Decoding an image with Stegano Module Question: I have a image file that i have to decode with Stegano module. I tried everything but always getting syntax error. Error: root@kali:~/Downloads/Stegano-master# stegano-lsb reveal -i predat0r.png Install Stegano: sudo pip install Stegano Traceback (most recent call last): File “/usr/local/bin/stegano-lsb”, line 32, in <module> from stegano import tools …

Total answers: 2

How to decode a QR-code image in (preferably pure) Python?

How to decode a QR-code image in (preferably pure) Python? Question: TL;DR: I need a way to decode a QR-code from an image file using (preferable pure) Python. I’ve got a jpg file with a QR-code which I want to decode using Python. I’ve found a couple libraries which claim to do this: PyQRCode (website …

Total answers: 9

Replacing = with 'x' and then decoding in python

Replacing = with 'x' and then decoding in python Question: I fetched the subject of an email message using python modules and received string ‘=D8=B3=D9=84=D8=A7=D9=85_=DA=A9=D8=AC=D8=A7=D8=A6=DB=8C?=’ I know the string is encoded in ‘utf-8’. Python has a method called on strings to decode such strings. But to use the method I needed to replace = sign …

Total answers: 3

UnicodeDecodeError, invalid continuation byte

UnicodeDecodeError, invalid continuation byte Question: Why is the below item failing? Why does it succeed with "latin-1" codec? o = "a test of xe9 char" #I want this to remain a string as this is what I am receiving v = o.decode("utf-8") Which results in: Traceback (most recent call last): File "<stdin>", line 1, in …

Total answers: 13

How to decode base64 url in python?

How to decode base64 url in python? Question: For Facebook fbml Apps Facebook is sending in a signed_request parameter explained here: http://developers.facebook.com/docs/authentication/canvas They have given the php version of decoding this signed request: http://pastie.org/1054154 How to do the same in python? I tried base64 module but I am getting Incorrect padding error: >>> base64.urlsafe_b64decode(“eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyNzk3NDYwMDAsIm9hdXRoX3Rva2VuIjoiMjk1NjY2Njk1MDY0fDIuRXpwem5IRVhZWkJVZmhGQ2l4ZzYzUV9fLjM2MDAuMTI3OTc0NjAwMC0xMDAwMDA0ODMyNzI5MjN8LXJ6U1pnRVBJTktaYnJnX1VNUUNhRzlNdEY4LiIsInVzZXJfaWQiOiIxMDAwMDA0ODMyNzI5MjMifQ”) Traceback …

Total answers: 9