Python Forum
Parse BytesIO data - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Parse BytesIO data (/thread-29125.html)



Parse BytesIO data - GrahamL - Aug-19-2020

Hi
I am new to Python and am writing some scripts for Jenkins.
I needed to get a Jenkins crumb which I have managed to do
The value received is
b'{"_class":"hudson.security.csrf.DefaultCrumbIssuer","crumb":"90fd32d5d18a2e84c9ec443fabd9800d4bfd9e22c9bdf29624c5be8b09a49a06","crumbRequestField":"Jenkins-Crumb"}'

My question is how do I access the value for "crumb"

Thanks


RE: Parse BytesIO data - ndc85430 - Aug-19-2020

Looks like JSON, so parse it into a Python dictionary using the json module.


RE: Parse BytesIO data - bowlofred - Aug-19-2020

How are you getting the bytes object in? It might be a bit easier to read the data directly as JSON.

But if you had to get it as bytes, you could decode() it to a str, and then read that into JSON (json.loads()) and can then pull the pieces out.