question

ObaidUrRehman-9153 avatar image
0 Votes"
ObaidUrRehman-9153 asked ObaidUrRehman-9153 answered

Deleting files from blob - TypeError: quote_from_bytes() expected bytes

Hi,
I have some files inside a container named data:

 folder1/somepath/folder2/output/folder3/my_file1.csv
 folder1/somepath/folder2/output/folder3/my_file4.csv
 folder1/somepath/folder2/output/folder3/my_file23.csv

I have the following code:

 file_names_prefix = os.path.join('folder1/somepath/','folder2','output','folder3','my_file')
 client = BlobServiceClient('https://mystoragename.blob.core.windows.net',credential=DefaultAzureCredential()).get_container_client('data')
 blob_list = client.list_blobs(name_starts_with=file_names_prefix)
 file_list = [blob.name for blob in blob_list]


The code above produces the following output:

 ['folder1/somepath/folder2/output/folder3/my_file1.csv',
  'folder1/somepath/folder2/output/folder3/my_file4.csv',
 'folder1/somepath/folder2/output/folder3/my_file23.csv']

but when trying to delete these files using:

 client.delete_blobs(file_list)

There is an error:

TypeError Traceback (most recent call last)
/tmp/ipykernel_2376/712121654.py in <module>
----> 1 client.delete_blobs(file_list)

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/azure/core/tracing/decorator.py in wrapper_use_tracer(args, *kwargs)
81 span_impl_type = settings.tracing_implementation()
82 if span_impl_type is None:
---> 83 return func(args, *kwargs)
84
85 # Merge span is parameter is set, but only if no explicit parent are passed

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/azure/storage/blob/_container_client.py in delete_blobs(self, blobs, *kwargs)
1298 return iter(list())
1299
-> 1300 reqs, options = self._generate_delete_blobs_options(blobs, *kwargs)
1301
1302 return self._batch_send(reqs, *options)

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/azure/storage/blob/_container_client.py in _generate_delete_blobs_options(self, blobs, *kwargs)
1206 req = HttpRequest(
1207 "DELETE",
-> 1208 "/{}/{}{}".format(quote(container_name), quote(blob_name, safe='/~'), self._query_str),
1209 headers=header_parameters
1210 )

/anaconda/envs/azureml_py38/lib/python3.8/urllib/parse.py in quote(string, safe, encoding, errors)
817 if errors is not None:
818 raise TypeError("quote() doesn't support 'errors' for bytes")
--> 819 return quote_from_bytes(string, safe)
820
821 def quote_plus(string, safe='', encoding=None, errors=None):

/anaconda/envs/azureml_py38/lib/python3.8/urllib/parse.py in quote_from_bytes(bs, safe)
842 """
843 if not isinstance(bs, (bytes, bytearray)):
--> 844 raise TypeError("quote_from_bytes() expected bytes")
845 if not bs:
846 return ''

TypeError: quote_from_bytes() expected bytes


Can someone please help?





azure-blob-storage
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ObaidUrRehman-9153 Firstly, apologies for the delay in responding here and any inconvenience this issue may have caused. I am checking on this thread

0 Votes 0 ·
AlexanderTarnavsky-6714 avatar image
0 Votes"
AlexanderTarnavsky-6714 answered

I'm getting the same error, did anybody have a solution or a workaround?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ObaidUrRehman-9153 avatar image
0 Votes"
ObaidUrRehman-9153 answered

Hi,

I tried various things but nothing helped, ended up using delete_blob in a loop:

for file in file_list:
client.delete_blob(file)


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.