Skip to content

Instantly share code, notes, and snippets.

@ivanrvpereira
Created May 16, 2016 14:46
Show Gist options
  • Save ivanrvpereira/7bc2b546ddc468ac26819cb0a011c78f to your computer and use it in GitHub Desktop.
Save ivanrvpereira/7bc2b546ddc468ac26819cb0a011c78f to your computer and use it in GitHub Desktop.
Converts base64 application/x-python-serialize in rabbitmq to human readable json for easier debug
import click
import base64
import pickle
import pprint
@click.command()
@click.argument('b64body')
@click.option('--indent', default=2, type=int)
def unserialize(b64body, indent):
m = "".join(b64body.strip().split("\n"))
try:
res = pickle.loads(base64.b64decode(m))
pp = pprint.PrettyPrinter(indent=indent)
click.echo("")
pp.pprint(res)
except TypeError:
click.echo("Cannot parse this base64 body")
from setuptools import setup
setup(
name='b64tojson',
version='0.1',
py_modules=['b64tojson'],
install_requires=[
'Click',
],
entry_points='''
[console_scripts]
b64tojson=b64tojson:unserialize
''',
)
@ivanrvpereira
Copy link
Author

Download both files to a directory and then inside the directory $ pip install .

@hbksagar
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment