Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Padding running example.py #24

Open
hemebond opened this issue Sep 16, 2021 · 2 comments
Open

Invalid Padding running example.py #24

hemebond opened this issue Sep 16, 2021 · 2 comments

Comments

@hemebond
Copy link

This issue is for a:

- [x] bug report
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

export AZURE_STORAGE_CONNECTIONSTRING="........"
git clone https://github.com/Azure-Samples/azure-sdk-for-python-storage-blob-upload-download.git
pip install -r requirements.txt
python example.py

Any log messages given by the failure

$ python example.py 
Incorrect padding

Expected/desired behavior

Runs example stuff.

OS and Version?

$ uname -a
Linux excession 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux

Versions

$ python --version
Python 3.8.8

$ pip list
Package              Version
-------------------- ---------
azure-common         1.1.27
azure-storage-blob   2.1.0
azure-storage-common 2.1.0
certifi              2021.5.30
cffi                 1.14.6
charset-normalizer   2.0.5
cryptography         3.4.8
idna                 3.2
pip                  20.2.3
pycparser            2.20
python-dateutil      2.8.2
requests             2.26.0
setuptools           49.2.1
six                  1.16.0
urllib3              1.26.6

Mention any other details that might be useful

Same issue as #17 and an error that occurs in other contexts (django-storages)

Here's an example of using BlobBlockService manually in iPython:

In [4]: blob_service_client = BlockBlobService(account_name=AZURE_ACCOUNT_NAME, account_key=AZURE_ACCOUNT_KEY)

In [5]: blob_service_client.exists(AZURE_CONTAINER)
---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
.../site-packages/azure/storage/common/_auth.py in _add_authorization_header(self, request, string_to_sign)
     68         try:
---> 69             signature = _sign_string(self.account_key, string_to_sign)
     70             auth_string = 'SharedKey ' + self.account_name + ':' + signature

.../site-packages/azure/storage/common/_common_conversion.py in _sign_string(key, string_to_sign, key_is_base64)
     90     if key_is_base64:
---> 91         key = _decode_base64_to_bytes(key)
     92     else:

.../site-packages/azure/storage/common/_common_conversion.py in _decode_base64_to_bytes(data)
     80         data = data.encode('utf-8')
---> 81     return base64.b64decode(data)
     82 

/usr/lib/python3.9/base64.py in b64decode(s, altchars, validate)
     86         raise binascii.Error('Non-base64 digit found')
---> 87     return binascii.a2b_base64(s)
     88 

Error: Incorrect padding

During handling of the above exception, another exception occurred:

AzureSigningError                         Traceback (most recent call last)
<ipython-input-5-7d5053a16991> in <module>
----> 1 blob_service_client.exists(AZURE_CONTAINER)

.../site-packages/azure/storage/blob/baseblobservice.py in exists(self, container_name, blob_name, snapshot, timeout)
   1757             expected_errors = [_CONTAINER_NOT_FOUND_ERROR_CODE] if blob_name is None \
   1758                 else [_CONTAINER_NOT_FOUND_ERROR_CODE, _BLOB_NOT_FOUND_ERROR_CODE]
-> 1759             self._perform_request(request, expected_errors=expected_errors)
   1760 
   1761             return True

.../site-packages/azure/storage/common/storageclient.py in _perform_request(self, request, parser, parser_args, operation_context, expected_errors)
    400                                 client_request_id_prefix,
    401                                 exception_str_in_one_line)
--> 402                     raise ex
    403 
    404                 logger.info("%s Operation failed: checking if the operation should be retried. "

.../site-packages/azure/storage/common/storageclient.py in _perform_request(self, request, parser, parser_args, operation_context, expected_errors)
    372                 except AzureException as ex:
    373                     retry_context.exception = ex
--> 374                     raise ex
    375                 except Exception as ex:
    376                     retry_context.exception = ex

.../site-packages/azure/storage/common/storageclient.py in _perform_request(self, request, parser, parser_args, operation_context, expected_errors)
    312                     try:
    313                         # request can be signed individually
--> 314                         self.authentication.sign_request(request)
    315                     except AttributeError:
    316                         # session can also be signed

.../site-packages/azure/storage/common/_auth.py in sign_request(self, request)
     90             self._get_canonicalized_resource_query(request)
     91 
---> 92         self._add_authorization_header(request, string_to_sign)
     93         logger.debug("String_to_sign=%s", string_to_sign)
     94 

.../site-packages/azure/storage/common/_auth.py in _add_authorization_header(self, request, string_to_sign)
     73             # Wrap any error that occurred as signing error
     74             # Doing so will clarify/locate the source of problem
---> 75             raise _wrap_exception(ex, AzureSigningError)
     76 
     77     def sign_request(self, request):

AzureSigningError: Incorrect padding
@lmazuel lmazuel removed their assignment Dec 27, 2021
@lmazuel
Copy link

lmazuel commented Dec 27, 2021

@tasherif-msft would be better owner than me on this.

@tasherif-msft
Copy link

Hi @hemebond, thanks for all the details.
@jalauzon-msft could you please have a look at this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants