Answer the question
In order to leave comments, you need to log in
How to convert string to json?
I make a GET request to gitlab:
url = 'https://gitlab.example/api/v4/projects/303/repository/commits/master/diff'
print(requests.get(url, headers={'Private-Token': 'blahblahblah'}).json())
Answer the question
In order to leave comments, you need to log in
You need to use .text instead of .json()
- json() deserializes json and turns it into a dict, replacing null with None, true/false with True/False so that python can work with it;
- text returns the content of the response as a string. In your case, if you received json in the content, then you will receive it there.
The fact that you were advised from above is like an overkill. Use another module to serialize to json when you already have it in response.text
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question