Home > front end >  GET API call returns non-text content
GET API call returns non-text content

Time:02-06

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

CodePudding user response:

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/

CodePudding user response:

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)
  •  Tags:  
  • Related