Python 3 Post JSON Requests to API -
i'm new @ python , have been reading how post json query requests module. reason following script doesn't work. have specified python3 version i'm using , version of requests module.
output is:
out[31]: <response [200]>
what mean? missing? need use params?
import sys print (sys.version) #3.6.1 |anaconda 4.4.0 (x86_64)| (default, may 11 2017, 13:04:09) #[gcc 4.2.1 compatible apple llvm 6.0 (clang-600.0.57)] import requests import json requests.__version__ #out[27]: '2.14.2' headers = {'content-type': 'application/json'} url = 'http://api.scb.se/ov0104/v1/doris/sv/ssd/start/be/be0101/be0101a/befolkningny' data = { "query": [ { "code": "region", "selection": { "filter": "vs:regionkommun07", "values": [ "0115", "0117", "0120" ] } }, { "code": "civilstand", "selection": { "filter": "item", "values": [ "og", "g" ] } }, { "code": "alder", "selection": { "filter": "agg:Ålder5år", "values": [ "15-19", "20-24" ] } }, { "code": "kon", "selection": { "filter": "item", "values": [ "1", "2" ] } }, { "code": "contentscode", "selection": { "filter": "item", "values": [ "be0101n1" ] } }, { "code": "tid", "selection": { "filter": "item", "values": [ "2013", "2014", "2015" ] } } ], "response": { "format": "px" } } requests.post(url, data=json.dumps(data), headers=headers)
Comments
Post a Comment