Azure / azure-storage-python

Microsoft Azure Storage Library for Python
https://azure-storage.readthedocs.io
MIT License
339 stars 241 forks source link

Bizarre traceback when incorrect account details are provided due to retry handler expecting 'context.request.body' to be present #481

Closed stewartadam closed 5 years ago

stewartadam commented 6 years ago

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

blob

Which version of the SDK was used? Please provide the output of pip freeze.

azure-storage-blob==1.3.1 azure-storage-common==1.3.0

What problem was encountered?

If user misconfigures the access credentials to their blob store, a obscure traceback is provided instead of an error when uploading any file via create_blob_from_* methods:

# ...
# flask-request-stuff
# ...
  File "/Users/stewartadam/code/flasktest/app/shapi/views.py", line 108, in post
    blob_service.create_blob_from_stream('attempts', blob_name, imageFile)
  File "/Users/stewartadam/code/virtualenvs/flasktest-xUdAmdfH/lib/python3.7/site-packages/azure/storage/blob/blockblobservice.py", line 645, in create_blob_from_stream
    encryption_data=encryption_data
  File "/Users/stewartadam/code/virtualenvs/flasktest-xUdAmdfH/lib/python3.7/site-packages/azure/storage/blob/blockblobservice.py", line 1062, in _put_block_list
    return self._perform_request(request, _parse_base_properties)
  File "/Users/stewartadam/code/virtualenvs/flasktest-xUdAmdfH/lib/python3.7/site-packages/azure/storage/common/storageclient.py", line 360, in _perform_request
    retry_interval = self.retry(retry_context)
  File "/Users/stewartadam/code/virtualenvs/flasktest-xUdAmdfH/lib/python3.7/site-packages/azure/storage/common/retry.py", line 218, in retry
    return self._retry(context, self._backoff)
  File "/Users/stewartadam/code/virtualenvs/flasktest-xUdAmdfH/lib/python3.7/site-packages/azure/storage/common/retry.py", line 154, in _retry
    if hasattr(context.request.body, 'read'):
AttributeError: 'NoneType' object has no attribute 'body'

Logging showed:

2018-08-03 12:35:51,437 azure.storage.common.storageclient INFO  Client-Request-ID=6e0fd270-9754-11e8-992f-72000494eae0 Operation failed: checking if the operation should be retried. Current retry count=0, , HTTP status code=Unknown, Exception=Incorrect padding.

Here's a flask_restful MVP:

from flask_restful import Resource, Api
#...
# create your app
#...

api = Api(app)

class FileHandler(Resource):
    def post(self):
        blob_service = BlockBlobService(account_name='accountname', account_key='accountkey')
        imageFile = request.files.get('image')
        blob_service.create_blob_from_stream('attempts', blob_name, imageFile)
        blob_url = blob_service.make_blob_url('mycontainername', 'myblobname')
        return blob_url

api.add_resource(HintAttempt, '/upload')

Have you found a mitigation/solution?

No

zezha-msft commented 6 years ago

Hi @stewartadam, thanks for reaching out!

I will investigate this issue and update this thread.

giggio commented 6 years ago

I got the same error when I incorrectly inverted account name and key:

az storage container delete -n $name --account-key $storageAccountName --account-name $storageAccountKey

The error message should be clearer.

zezha-msft commented 6 years ago

Hi @giggio, I apologize for the inconvenience. We've fixed it and are waiting for a release to publish it.

zezha-msft commented 5 years ago

Fixed in 1.4.0.