mapillary / mapillary-python-sdk

A Python 3 library built on the Mapillary API v4 to facilitate retrieving and working with Mapillary data.
MIT License
37 stars 14 forks source link

Bug Report: 403 forbidden when requesting image close to #131

Closed cbeddow closed 2 years ago

cbeddow commented 2 years ago

Describe the bug Vector tile request is rejected with a 403 error when a request is made

To Reproduce

  1. Set access token
  2. run a basic close_to request:
data = mly.get_image_close_to(longitude=31, latitude=30).to_dict()

Expected behavior Should return a dictionary stored in the data variable

Screenshots

Requesting GET to https://tiles.mapillary.com/maps/vtp/mly1_public/2/14/9602/6759/
Response 403 Forbidden received in 181ms
Server responded with a 403 error!
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_47044/402950844.py in <module>
      1 # 8.310867547988892, 47.05843594638918
----> 2 data = mly.get_image_close_to(longitude=31, latitude=30).to_dict()

C:\Python38\lib\site-packages\mapillary\utils\auth.py in wrapper(*args, **kwargs)
     58 
     59             # Return function called with arguments
---> 60             return f(*args, **kwargs)
     61 
     62         # Return wrapper

C:\Python38\lib\site-packages\mapillary\interface.py in get_image_close_to(latitude, longitude, **kwargs)
    108     """
    109 
--> 110     return image.get_image_close_to_controller(
    111         latitude=latitude,
    112         longitude=longitude,

C:\Python38\lib\site-packages\mapillary\controller\image.py in get_image_close_to_controller(longitude, latitude, kwargs)
    101     image_check(kwargs=kwargs)
    102 
--> 103     unfiltered_data = VectorTilesAdapter().fetch_layer(
    104         layer="image",
    105         zoom=kwargs["zoom"] if "zoom" in kwargs else 14,

C:\Python38\lib\site-packages\mapillary\models\api\vector_tiles.py in fetch_layer(self, layer, longitude, latitude, zoom)
    117 
    118         # Return the results of the layer after preprocessing steps
--> 119         return self.__preprocess_layer(
    120             # The layer to retrieve from
    121             layer=layer,

C:\Python38\lib\site-packages\mapillary\models\api\vector_tiles.py in __preprocess_layer(self, layer, tile, zoom)
    488         return vt_bytes_to_geojson(
    489             # Parameters, appropriately
--> 490             b_content=self.client.get(url).content,
    491             x=tile.x,
    492             y=tile.y,

C:\Python38\lib\site-packages\mapillary\models\client.py in get(self, url, params)
    195         self.session.headers.update({"Authorization": f"OAuth {self.__access_token}"})
    196 
--> 197         return self._initiate_request(url=url, method="GET", params=params)
    198 
    199     @staticmethod

C:\Python38\lib\site-packages\mapillary\models\client.py in _initiate_request(self, url, method, params)
    174                 )
    175 
--> 176             res.raise_for_status()
    177 
    178         return res

C:\Python38\lib\site-packages\requests\models.py in raise_for_status(self)
    941 
    942         if http_error_msg:
--> 943             raise HTTPError(http_error_msg, response=self)
    944 
    945     def close(self):

HTTPError: 403 Client Error: Forbidden for url: https://tiles.mapillary.com/maps/vtp/mly1_public/2/14/9602/6759/

Additional context Running latest version just installed today with pip install

cbeddow commented 2 years ago

I believe this is because the token is sent to the vector tile request in the header but the vector tile endpoint, unlike the API, wants the token only in the URL itself as ?access_token=MLY|XXX

Rubix982 commented 2 years ago

Small change, but worth a try.

I'll get to it this week.

OmarMuhammedAli commented 2 years ago

Hey guys! I can work on this issue this weekend if you want

cbeddow commented 2 years ago

Sounds good either way @OmarMuhammedAli !

I am going to make a short video with a demo of the SDK which people will probably see Friday, so some may be testing it over the weekend too--if you fix it, make a release!

Rubix982 commented 2 years ago

That would be great, @OmarMuhammedAli!

Best wishes.

cbeddow commented 2 years ago

@OmarMuhammedAli did you manage to find a best solution here? Is it easiest to just force appending the access token to the tile URL?

OmarMuhammedAli commented 2 years ago

Hey @cbeddow, sorry for the late response; I was pretty occupied with midterms these past 2 weeks so, unfortunately, I didn't have much time to work on the issue. I'll get back on it asap. Hopefully, I'll get it done by the end of this weekend!

Rubix982 commented 2 years ago

Closing.