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

Python 2.7.10 Mac OS X 10.10 - binascii.Error TypeError: Incorrect padding #31

Closed
rocket-ron opened this issue Aug 28, 2015 · 2 comments

Comments

@rocket-ron
Copy link

I have the following code:

 key = 'my_storage_account_key'
 blob_service = BlobService(account_name='my_storage_account', account_key='key')
 container = u'test'
 containers = blob_service.list_containers()

which results in the following error:

 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call last)
 <ipython-input-15-5ecff0813140> in <module>()
       3 
       4 container = u'test'
 ----> 5 containers = blob_service.list_containers()
       6 if container not in containers:
       7     try:

 /Users/emh5y7u/Documents/MIDS/W205/W205env/lib/python2.7/site-    packages/azure/storage/blob/blobservice.pyc in list_containers(self, prefix, marker, maxresults, include)
     291             request, self.use_local_storage)
     292         request.headers = _update_storage_blob_header(
 --> 293             request, self.authentication)
     294         response = self._perform_request(request)
     295 

 /Users/emh5y7u/Documents/MIDS/W205/W205env/lib/python2.7/site-packages/azure/storage/blob/_serialization.pyc in _update_storage_blob_header(request, authentication)
      41     request.headers.append(
      42         ('Content-Type', 'application/octet-stream Charset=UTF-8'))
 ---> 43     authentication.sign_request(request)
      44 
      45     return request.headers

 /Users/emh5y7u/Documents/MIDS/W205/W205env/lib/python2.7/site-packages/azure/storage/auth.pyc in sign_request(self, request)
      68             self._get_canonicalized_resource_query(request)
      69 
 ---> 70         self._add_authorization_header(request, string_to_sign)
      71 
      72     def _get_canonicalized_resource_query(self, request):

 /Users/emh5y7u/Documents/MIDS/W205/W205env/lib/python2.7/site-packages/azure/storage/auth.pyc in _add_authorization_header(self, request, string_to_sign)
      47 
      48     def _add_authorization_header(self, request, string_to_sign):
 ---> 49         signature = _sign_string(self.account_key, string_to_sign)
      50         auth_string = 'SharedKey ' + self.account_name + ':' + signature
      51         request.headers.append(('Authorization', auth_string))

 /Users/emh5y7u/Documents/MIDS/W205/W205env/lib/python2.7/site-packages/azure/storage/_common_conversion.pyc in _sign_string(key, string_to_sign, key_is_base64)
      81 def _sign_string(key, string_to_sign, key_is_base64=True):
      82     if key_is_base64:
 ---> 83         key = _decode_base64_to_bytes(key)
      84     else:
      85         if isinstance(key, _unicode_type):

 /Users/emh5y7u/Documents/MIDS/W205/W205env/lib/python2.7/site-packages/azure/storage/_common_conversion.pyc in _decode_base64_to_bytes(data)
      71     if isinstance(data, _unicode_type):
      72         data = data.encode('utf-8')
 ---> 73     return base64.b64decode(data)
      74 
      75 

  /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.pyc in b64decode(s, altchars)
      74     except binascii.Error, msg:
      75         # Transform this exception for consistency
 ---> 76         raise TypeError(msg)
      77 
      78 

 TypeError: Incorrect padding

I've copied the key correctly, I've tried base64 encoding the key but I can't seem to establish a connection to the storage account. I'm not sure what else to try...

@emgerner-msft
Copy link
Member

You don't need to base64 encode the key -- just pass in directly what you got from the portal or wherever else you got the key from. I know you said you've copied correctly, but two things to confirm right off the bat since they're common errors:

  1. Does the key you're passing have whitespace around it? If so, make sure you remove that.
  2. Many keys have = signs in them or end in that character. If your key ends in symbols, they are indeed part of the key and should be included.

Tell me either way and if these aren't the issues we'll keep debugging!

@rocket-ron
Copy link
Author

I created a completely clean Python 2.7 virtualenv and reloaded the Azure SDK and Azure storage modules. All works ok now.

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

2 participants