Hi @chrisbeddow !
Thank you for your recommendations!
I’m using a map feature search because I need filtered results for a large area. I mean, I’m trying to reduce the number of requests needed to get the data I’m interested in.
Here is a code similar to what I’m using:
import json
import mercantile
import requests
from requests.exceptions import HTTPError
TOKEN = "MLY|7...d"
QUADKEY = "023110"
LIMIT = 2000
def main():
params = {
"fields": "id,geometry,aligned_direction,object_value,object_type",
"start_first_seen_at": "2021-10-01T00:00:00+0000",
"end_first_seen_at": "2022-01-01T00:00:00+0000",
"start_last_seen_at": "2021-10-01T00:00:00+0000",
"end_last_seen_at": "2022-01-01T00:00:00+0000",
"object_values": "regulatory--no-left-turn--g*",
"limit": LIMIT,
"bbox": quadkey_to_bbox(QUADKEY),
}
headers = {
"Content-Type": "application/json",
"Authorization": f"OAuth {TOKEN}",
}
print(json.dumps(params, indent=2))
response_content = search_map_features(params, headers)
print(json.dumps(response_content, indent=2))
print(len(response_content["data"]))
def search_map_features(params, headers):
with requests.Session() as session:
response = session.get("https://graph.mapillary.com/map_features", params=params, headers=headers)
if response.status_code != requests.codes.ok:
raise_http_error(response)
return response.json()
def raise_http_error(response):
if isinstance(response.reason, bytes):
try:
reason = response.reason.decode("utf-8")
except UnicodeDecodeError:
reason = response.reason.decode("iso-8859-1")
else:
reason = response.reason
http_error_message = f"{response.status_code} HTTP Status: {reason} for url: {response.url}"
raise HTTPError(http_error_message, response=response)
def quadkey_to_bbox(quadkey):
tile = mercantile.quadkey_to_tile(quadkey)
bbox = mercantile.bounds(tile)
return f"{bbox.west},{bbox.south},{bbox.east},{bbox.north}"
if __name__ == "__main__":
main()
Sometimes this code returns the following result:
{
"fields": "id,geometry,aligned_direction,object_value,object_type",
"start_first_seen_at": "2021-10-01T00:00:00+0000",
"end_first_seen_at": "2022-01-01T00:00:00+0000",
"start_last_seen_at": "2021-10-01T00:00:00+0000",
"end_last_seen_at": "2022-01-01T00:00:00+0000",
"object_values": "regulatory--no-left-turn--g*",
"limit": 2000,
"bbox": "-101.25,36.59788913307021,-95.625,40.97989806962013"
}
{
"data": [
{
"id": "1059714538214858",
"geometry": {
"type": "Point",
"coordinates": [
-96.548783633697,
39.189423358123
]
},
"aligned_direction": 273.93481148483,
"object_value": "regulatory--no-left-turn--g1",
"object_type": "trafficsign"
},
{
"id": "1059714571548188",
"geometry": {
"type": "Point",
"coordinates": [
-96.548449367512,
39.189418245144
]
},
"aligned_direction": 274.80228197329,
"object_value": "regulatory--no-left-turn--g1",
"object_type": "trafficsign"
},
{
"id": "623827028704848",
"geometry": {
"type": "Point",
"coordinates": [
-99.096355950596,
40.699431403659
]
},
"aligned_direction": 87.11265738214,
"object_value": "regulatory--no-left-turn--g1",
"object_type": "trafficsign"
}
]
}
3
But in most cases, it fails with a 500 HTTP Status code.
Traceback (most recent call last):
...
raise HTTPError(http_error_message, response=response)
requests.exceptions.HTTPError: 500 HTTP Status: Internal Server Error for url: https://graph.mapillary.com/map_features?fields=id%2Cgeometry%2Caligned_direction%2Cobject_value%2Cobject_type&start_first_seen_at=2021-10-01T00%3A00%3A00%2B0000&end_first_seen_at=2022-01-01T00%3A00%3A00%2B0000&start_last_seen_at=2021-10-01T00%3A00%3A00%2B0000&end_last_seen_at=2022-01-01T00%3A00%3A00%2B0000&object_values=regulatory--no-left-turn--g%2A&limit=2000&bbox=-101.25%2C36.59788913307021%2C-95.625%2C40.97989806962013
I agree with @eserte that exceptions have become more frequent after 2022-01-27.