[Python] Python requests .json() function do not raise an exception [closed]

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    According the Python requests documentation there should be raised an exception if on a not valid json string in a response the .json() function is applied.

    But in my case there is a "normal" evaluation performed!

    >>> import requests
    >>> r = requests.get(myUrl)
    >>> r.text
    '3.14'
    >>> r.content
    b'3.14'
    >>> r.encoding
    'utf-8'
    >>> r.json()
    3.14
    >>> type(r.json())
    <class 'float'>
    >>>


    Why is a no requests.exceptions.JSONDecodeError exception raised?

    System Info: Ubuntu 22.04.5 64-bit, Python 3.12.3, requests 2.32.3.

    Continue reading...

Compartilhe esta Página