Hi,
I’m trying to fetch traffic stats via the Python API, here’s the snippet of code I’m using:
import json
import requests
req_str = """
{
"jobName":"Test job",
"distanceUnit":"KILOMETERS",
"network": {
"name": "test",
"geometry" : {
"type": "MultiPolygon",
"coordinates": [
[
[
[19.44305, 51.75612],
[19.44992, 51.75612],
[19.44992, 51.75947],
[19.44305, 51.75947],
[19.44305, 51.75612]
]
],
[
[
[19.45011, 51.75789],
[19.45687, 51.75789],
[19.45687, 51.75946],
[19.45011, 51.75946],
[19.45011, 51.75789]
]
]
]
},
"timeZoneId": "Europe/Warsaw",
"frcs": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
],
"probeSource":"ALL"
},
"dateRange": {
"name":"Last working week of April",
"from":"2015-04-24",
"to":"2015-04-30",
"exclusions":[
"2015-04-25",
"2015-04-26"
]
},
"timeSets":[
{
"name":"Monday morning hour",
"timeGroups":[
{
"days":[
"MON"
],
"times":[
"7:00-8:00"
]
}
]
}
]
}
"""
test_req_json = json.loads(req_str)
BASEURL = 'api.tomtom.com'
VERSION = 1
API_KEY = 'my_key_here'
full_url = 'https://{baseurl}/traffic/trafficstats/trafficdensity/{version}?key={apikey}'.format(
baseurl=BASEURL, version=VERSION, apikey=API_KEY)
post_response = requests.post(full_url, json=test_req_json, headers={'Content-Type': 'application/json'})
print(post_response)
print(post_response.content)
I see this response:
<Response [403]>
b'<h1>Developer Inactive</h1>'
I’ve tried this same API key to get Traffic flow, which works:
https://api.tomtom.com/traffic/services/4/flowSegmentData/relative0/10/json?point=52.41072%2C4.84239&unit=KMPH&key=*****
so I don’t think it’s the API key.
The request JSON is also from the example request in the traffic stats documentation:
Can someone help me figure out what I’m doing wrong?
Thanks!