B
B
BotaniQ_Q2017-06-18 16:12:28
Python
BotaniQ_Q, 2017-06-18 16:12:28

Parsing json in python throws an error?

There is a site that gives us json, I want to access it, take a string with a certain key ("output:") and then work with it as a variable, in this output there are lines in Russian with a broken encoding (I would also restore it, I try to restore encodings on the site - it turns out :)) In short, there are a lot of problems, here is my code

url = 'сайт.ком.json'+'Привет, Мир'
response = requests.get(url)

print(response.json())

1) Python swears at the last line, what exactly the error does not say, json is definitely there.
2) In this json encodings are down, if done through javascript like this
<script>
url = "сайт.ком.json";
input = encodeURIComponent ("Привет, мир");
function ProcessReply (data) {
    if (data.error) console.log ('Error: ' + data.error);
    else alert ('Reply: ' + data.output);
}
script_element = document.createElement('script'); //create new script element
script_element.src = url + "?input=" + input ;
document.getElementsByTagName ('head')[0].appendChild(script_element); //append to page, which executes it
</script>

then the text is returned Russian, normal, human
3) Well, the next thing I don’t know is how I can get not all json, but only the one that is "output:"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan, 2017-06-18
@rOOse

Without json, it is not clear why the python swears and what is there with the encoding, get by key like this:print(response.json()['output:'])

D
Dmitry, 2017-06-18
@LazyTalent

print(response.text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question