import requests b=requests.get(r"http://rzhunemogu.ru/RandJSON.aspx?CType=1").json() 

Why in some cases (because it gives random jokes) this code gives an error (possibly due to encodings) and how can I fix it?

  • one
    because your server sometimes returns incorrect json, namely some strings contain unscreened quotes, for example {"key": "строка "с" кавычками"} . Quotation marks inside strings must be escaped by adding a backslash (``) in front of them - diraria
  • Clear. Russian characters are not translated. You do not know how to fix it - Gleb
  • well, more lines in json cannot have line breaks , so all line breaks need to be replaced with \n - diraria
  • yes, but in fact there are \ n there. - Gleb
  • one
    if the code is \n , then json'e produces line breaks. Therefore, the code should be \\n , then json'e will be obtained \n - diraria

0