-
The two lines I've given just replace the existing
requests.get
line. [EDIT] Copied the code from the wrong example so I've updated it now.The link to the alternating problem was to highlight that it "should" change its behaviour based on the value of the
Accept
header, albeit with some bug in the server's implementation.With no header provided (as your existing code does) it may default to XML.
It may appear as JSON when viewed in the browser because the browser is providing the accept header set with it set to (amongst other things)
application/json
.
It might need you to specify the
Accept: application/json
header to tell the server you definitely want the response in JSON.Vaguely related: https://techforum.tfl.gov.uk/t/json-vs-xml-random-content-type-in-response/2238/13