0

I am making an API call and reading the response in JSON

r = requests.get(query_url, headers=headers)
pprint(r.json())

But the 'content' is not in text format

'content': 'CmRlbGV0ZSBmcm9tICB7eyBwYXJhbXMuY3VyYXRlZF9kYXRhYmFzZV9uYW1l\n'
           'IH19LmNybS5BRkZJTElBVEVfUFJJQ0lORzsKCklOU0VSVCBJTlRPICB7eyBw\n'
           'TkcKICB3aGVyZSAxID0gMQogIAogIDsKICAKICAKCg==\n'

How do I convert the 'content' to text

For full context, I am trying to download code from the GitHub repo as text to store in our Database

reachbgk
  • 83
  • 1
  • 8
  • 1
    Does this answer your question? [How do you decode Base64 data in Python?](https://stackoverflow.com/questions/3470546/how-do-you-decode-base64-data-in-python) – CherryDT Feb 05 '22 at 00:59
  • @CherryDT , yes that helped. I can now see all the text. Thank you for pointing me to the article – reachbgk Feb 05 '22 at 12:45

2 Answers2

0

Are you using python and in particular the requests package? If so, I think you could use r.text.

docs: https://pypi.org/project/requests/

Cchor
  • 21
  • 6
  • Yes, I am using python. I tried `r.text` but I get the same content – reachbgk Feb 05 '22 at 00:45
  • and is the endpoint really returning a json? you may check out the headers in the response or even set the content-type header in the request – Cchor Feb 05 '22 at 01:57
0

Thanks to the article @CherryDT pointed me to, I was able to get the text

import base64
r_dict = r.json()
content = r_dict['content']
base64.b64decode(content)
reachbgk
  • 83
  • 1
  • 8