Skip to content

The specified resource does not exist. #469

@ttelfer

Description

@ttelfer

Which service(blob, file, queue) does this issue concern?

File

What problem was encountered?

I get the following error when I attempt to initialize the FileService class. The following was working fine and then without notice it stopped working and started giving the following error:

Client-Request-ID=bc4ba635-7aef-11e8-be6a-000d3a319612 Retry policy did not allow for a retry: Server-Timestamp=Thu, 28 Jun 2018 16:24:31 GMT, Server-Request-ID=7ee390c2-c01a-0081-0efc-0e9221000000, HTTP status code=404, Exception=The specified resource does not exist.ErrorCode: ResourceNotFoundResourceNotFoundThe specified resource does not exist.RequestId:7ee390c2-c01a-0081-0efc-0e9221000000Time:2018-06-28T16:24:31.0526845Z.

I have verified that I am able to create a share and upload a file through the web interface without issue. Any help would be greatly appreciated

import os
import io
from typing import List
from tempfile import TemporaryFile
import csv

from azure.storage.file import (
    FileService,
    ContentSettings,
)
from azure.storage.common.retry import (
    ExponentialRetry,
    LinearRetry,
    no_retry,
)

ACCOUNT_NAME = '*****'
ACCOUNT_KEY = '*****'

SHARE_NAME = '*****'



class AzureFileShare():
    def __init__(self):
        try:
            self.file_service = FileService(
                account_name=ACCOUNT_NAME,
                account_key=ACCOUNT_KEY
            )

            self.file_service.retry = ExponentialRetry(initial_backoff=30, increment_base=2, max_attempts=30).retry
            # Use a default linear retry policy instead
            self.file_service.retry = LinearRetry().retry
            # Turn off retries
            self.file_service.retry = no_retry
        except Exception as e:
            print(e)
            raise Exception(e)

    def upload_files(self,
                                file_paths: List[str]):
        for f in file_paths:
             self.file_service.create_file_from_path(
                        SHARE_NAME,
                        None,
                        filename,
                        f,
                        content_settings=ContentSettings(content_type=CONTENT_TYPE[file_extension])
             )

        return

    def retrieve_file_in_directory(self,
                                   filename: str) -> io.StringIO:
        f = self.retrieve_file_in_directory_in_bytes(filename)

        return io.StringIO(f.decode('utf-8'))

    def retrieve_file_in_directory_in_bytes(self,
                                            filename: str) -> bytes:
        with TemporaryFile() as t:
            output_stream = io.BytesIO()

            try:
                file = self.file_service.get_file_to_stream(
                    SHARE_NAME,
                    None,
                    filename,
                    output_stream
                )
            except Exception as e:
                raise Exception(e)

            value = output_stream.getvalue()

            t.write(value)
            t.seek(0)

            return t.read()

if __name__ == '__main__':
    fileshare = AzureFileShare()

    files = ["/temp/file.csv"]

    fileshare.upload_files(files)

    file = fileshare.retrieve_file_in_directory("file.csv")

    for row in csv.reader(file, delimiter=','):
        print(row)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions