Skip to content
Advertisement

Parameters are ignored in python web request for JSON data

I try to read JSON-formatted data from the following public URL: http://ws-old.parlament.ch/factions?format=json. Unfortunately, I was not able to convert the response to JSON as I always get the HTML-formatted content back from my request. Somehow the request seems to completely ignore the parameters for JSON formatting passed with the URL:

JavaScript

Does somebody know how I am able to get the JSON formatted content as displayed in the web browser?

Advertisement

Answer

You need to add "Accept": "text/json" to request header.

For example using requests package:

JavaScript

Result:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement