Global AI and Data Science

 View Only
  • 1.  cannot download file

    Posted Sun April 26, 2020 08:39 AM

    I am trying to go through the following notebook. https://developer.ibm.com/tutorials/working-with-geospatial-vector-data-in-python

    It is written really well but at the end, I am getting an error message. Been trying to understand what I am doing wrong. This is the block of code that is, I think, causing it:

    # define the helper function

    def download_file_to_local(project_filename, local_file_destination=None, project=None):

        """

        Uses project-lib to get a bytearray and then downloads this file to local.

        Requires a valid `project` object.

       

        Args:

            project_filename str: the filename to be passed to get_file

            local_file_destination: the filename for the local file if different

           

        Returns:

            0 if everything worked

        """

       

        project = project

       

        # get the file

        print("Attempting to get file {}".format(project_filename))

        _bytes = project.get_file(project_filename).read()

       

        # check for new file name, download the file

        print("Downloading...")

        if local_file_destination==None: local_file_destination = project_filename

       

        with open(local_file_destination, 'wb') as f:

            f.write(bytearray(_bytes))

            print("Completed writing to {}".format(local_file_destination))

           

        return 0

    The Second code block:

    download_file_to_local('london_pois.zip', project=project)

    zipfile = "zip://./london_pois.zip!london_pois/london_pois.dbf"

    pois = gpd.read_file(zipfile)

    This is the error message:

    Attempting to get file london_pois.zip
    2020-04-26 12:16:21,947 - __PROJECT_LIB__ - ERROR - Project___get_file_name_from_asset_metadata(): asset name [london_pois.zip] can not be found!
    ---------------------------------------------------------------------------
    RuntimeError Traceback (most recent call last)
    <ipython-input-228-b1f651d5708a> in <module>
    ----> 1 download_file_to_local('london_pois.zip', project=project)
    2 zipfile = "zip://./london_pois.zip!london_pois/london_pois.dbf"
    3 pois = gpd.read_file(zipfile)

    <ipython-input-227-bcdb30c6cafe> in download_file_to_local(project_filename, local_file_destination, project)
    17 # get the file
    18 print("Attempting to get file {}".format(project_filename))
    ---> 19 _bytes = project.get_file(project_filename).read()
    20
    21 # check for new file name, download the file

    /opt/conda/envs/Python36/lib/python3.6/site-packages/project_lib/project.py in get_file(self, file_name, direct_storage, direct_os_retrieval)
    214 final_file_name = [file_name]
    215 if (not direct):
    --> 216 final_file_name = self._get_file_name_from_asset_metadata(file_name)
    217
    218 if (final_file_name is None):

    /opt/conda/envs/Python36/lib/python3.6/site-packages/project_lib/project.py in _get_file_name_from_asset_metadata(self, asset_name)
    522 asset_id = self._core.get_asset_id_from_asset_name(asset_name)
    523 if (not asset_id):
    --> 524 logger.log_and_throw("Project___get_file_name_from_asset_metadata(): asset name [{}] can not be found!".format(asset_name))
    525
    526 # fetch data object keys

    /opt/conda/envs/Python36/lib/python3.6/site-packages/project_lib/utils/logger.py in log_and_throw(self, err_msg)
    50 # see https://github.ibm.com/ax/planning/issues/4946
    51 self.logger.error(err_msg)
    ---> 52 raise RuntimeError(err_msg)
    53
    54 def log_and_throw_response(self, method_name, res_status_code, res_text):

    RuntimeError: Project___get_file_name_from_asset_metadata(): asset name [london_pois.zip] can not be found!



    ------------------------------
    naveen ganpat
    ------------------------------

    #GlobalAIandDataScience
    #GlobalDataScience


  • 2.  RE: cannot download file

    Posted Mon April 27, 2020 03:44 AM
    Hi Naveen, have you uploaded the file london_pois.zip to object store? Let me know if this does not solve it.

    ------------------------------
    Margriet Groenendijk
    ------------------------------



  • 3.  RE: cannot download file

    Posted Sun May 03, 2020 08:51 AM

    Dear Margriet,

    Many thanks for your response.

    I understand from this that I have to upload the file to object storage. This is what I did, please see screenshot.

    What I am missing is guidance how to connect this file to the notebook. Already I add the project token to my notebook as mentioned in the beginning of the notebook.

    Can you point me to the next step, please?

    Thanks,

    Naveen



    ------------------------------
    naveen ganpat
    ------------------------------