Http compression headers are required starting from 1.6.

53 views
Skip to first unread message

Solita / Jaakko

unread,
Mar 19, 2020, 11:14:52 AM3/19/20
to rata_digi...@googlegroups.com
Hello,

Http compression headers are required starting from 1.6.

You can of course start using the header right away.

Compression provides significant advantages:
1) Cheaper bandwidth costs
2) Faster requests

#1 is the main reason we're requiring the header

To use http compression, please include "accept-encoding: gzip" header in your request. Most libraries do this automatically

Br. Jaakko / Digitraffic

Teemu Sirkiä

unread,
Mar 19, 2020, 11:53:09 AM3/19/20
to rata.digitraffic.fi
Jos joku sattuu käyttämään Pythonia ilman mitään fiksumpaa http-kirjastoa, niin tästä voi olla iloa.

import json
from gzip import GzipFile
from urllib.request import urlopen, Request

url = 'https://rata.digitraffic.fi/api/v1/live-trains'
with urlopen(Request(url, headers={"Accept-Encoding": "gzip"})) as response, GzipFile(fileobj=response) as gf:
    data = json.loads(gf.read().decode('utf-8'))
    for x in data:
        print(x['trainType'], x['trainNumber'])

Solita / Jaakko

unread,
Apr 30, 2020, 6:20:59 AM4/30/20
to rata.digitraffic.fi

We decided to throttle unpacked requests before rejecting them completely. This is intented to give a soft "early warning" to developers. Timetable for throttling unpacked requests is as follows:

5.5.2020:    60 requests/minute
12.5.2020:   30 requests/minute
19.5.2020:   10 requests/minute
26.5.2020: 5 requests/minute 2.6.2020: unpacked requests are not allowed
Reply all
Reply to author
Forward
0 new messages