Closed khamaileon closed 1 year ago
Probably Mapbox changed smth on their isochrone endpoint. Could you check? With dry_run=True
you should just get the URL & parameters.
url:
https://api.mapbox.com/directions/v5/mapbox/walking?access_token=token
Parameters:
{
"headers": {
"User-Agent": "routingpy/v0.0.post296+g2357ccd",
"Content-Type": "application/x-www-form-urlencoded"
},
"timeout": 60,
"data": {
"coordinates": "13.413706,52.490202;13.421838,52.514105;13.453649,52.507987;13.401947,52.543373"
}
}
url:
https://api.mapbox.com/isochrone/v1/mapbox/walking/13.413706,52.490202?access_token=token&contours_minutes=10%2C20
Parameters:
{
"headers": {
"User-Agent": "routingpy/v0.0.post296+g2357ccd",
"Content-Type": "application/x-www-form-urlencoded"
},
"timeout": 60,
"data": {
"coordinates": "13.413706,52.490202;13.421838,52.514105;13.453649,52.507987;13.401947,52.543373"
}
}
The 2 queries work independently.
It works if I instantiate 2 clients.
client = MapboxOSRM(api_key='token')
client2 = MapboxOSRM(api_key='token')
route = client.directions(locations=coords, profile='walking')
isochrones = client2.isochrones(locations=coords[0], profile='walking', intervals=[600, 1200])
Haha what?! The 403 error in the first example is usually "unauthorized". What happens if you use Postman or so and do it similarly? I can't imagine what differs when you instantiate 2 clients.. it's still the same user agent, IP etc..
I put 2 prints here:
With the same client, I got:
https://api.mapbox.com/directions/v5/mapbox/walking?access_token=token
{'User-Agent': 'routingpy/v0.0.post296+g2357ccd', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': '105'}
https://api.mapbox.com/isochrone/v1/mapbox/walking/13.413706,52.490202?access_token=token&contours_minutes=10%2C20
{'User-Agent': 'routingpy/v0.0.post296+g2357ccd', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': '105'}
With different clients:
https://api.mapbox.com/directions/v5/mapbox/walking?access_token=token
{'User-Agent': 'routingpy/v0.0.post296+g2357ccd', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': '105'}
https://api.mapbox.com/isochrone/v1/mapbox/walking/13.413706,52.490202?access_token=token&contours_minutes=10%2C20
{'User-Agent': 'routingpy/v0.0.post296+g2357ccd', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded'}
As you can see, there is a problem with request headers.
So it's either Content-Length
header on the isochrone request or the keep-alive
connection? I'd assume it's the former, as it seems that's a GET request which doesn't have any content, so maybe their CloudFront proxy denies that? Who's setting that header? Is it us or requests
? Can you try without?
I think that's where the problem comes from. The same session and therefore the same headers are reused. Cloudfront must validate the content-length.
I'll take a look later in the day or tomorrow.
Right, that's not good. Thanks for the investigation!
It's strange though that a Session object would just keep all those headers and not re-compute them per request, but maybe I'm not understanding some of the subtleties around that.. For me this is only about session pooling so we can keep a connection alive, which should be more performant than opening a new one for each request..
Does it also do that if you turn the requests around? First GET, then POST, and it won't set a content length? I'm almost inclined to assume that's a bug in requests
..
Does it also do that if you turn the requests around? First GET, then POST, and it won't set a content length? I'm almost inclined to assume that's a bug in requests..
Yes it works that way.
In the end, it was just a pointer issue :)
fixed in #111
Here's what I did
Here's what I got
Here's what I was expecting
Result of the 2 requests
Here's what I think could be improved
At first I thought the calls must be too close together. So I added a time.sleep between them, but without success.