title: How to create a Shared Access Signature for a container with the Azure Python SDK
body: <p>I am trying to create a valid Shared Access Signature URL for a container in Azure storage, using the Azure Python SDK.  I'm trying to generate it to be effective immediately, to expire after 30 days, and to give read &amp; write access to the whole container (not just the blob).  The below code works fine, and it prints the final URL at the end.  I also manually verified in the portal that the container and blob were successfully created.</p>
  
  <p>However, after pasting the URL into a browser, I receive the following error message:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  -&lt;Error&gt;
  
  &lt;Code&gt;AuthenticationFailed&lt;/Code&gt;
  
  &lt;Message&gt;Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:adecbe4e-0001-007c-0d19-40670c000000 Time:2015-12-26T20:10:45.9030215Z&lt;/Message&gt;
  
  &lt;AuthenticationErrorDetail&gt;Signature fields not well formed.&lt;/AuthenticationErrorDetail&gt;
  
  &lt;/Error&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>It seems the issue must be with this line of code:</p>
  
  <pre><code>sasToken = blob_service.generate_shared_access_signature(containerName, None,SharedAccessPolicy(AccessPolicy(None, todayPlusMonthISO, "rw"), None))
  </code></pre>
  
  <p>Here is the full code sample:</p>
  
  <pre><code>from azure.storage.blob import BlobService
  import datetime
  from azure.storage import AccessPolicy, CloudStorageAccount, SharedAccessPolicy
  
  containerName = "testcontainer"
  blobName = "testblob.txt"
  azureStorageAccountName = "" # Removed for publishing to StackOverflow
  azureStorageAccountKey = "" # Removed for publishing to StackOverflow
  blob_service = BlobService(account_name=azureStorageAccountName, account_key=azureStorageAccountKey)
  blob_service.create_container(containerName)
  blob_service.put_block_blob_from_text(containerName,blobName,"Hello World")
  today = datetime.datetime.utcnow()
  todayPlusMonth = today + datetime.timedelta(30)
  todayPlusMonthISO = todayPlusMonth.isoformat()
  sasToken = blob_service.generate_shared_access_signature(containerName, None,SharedAccessPolicy(AccessPolicy(None, todayPlusMonthISO, "rw"), None))
  url = "https://" + azureStorageAccountName + ".blob.core.windows.net/" + containerName + "/" + blobName + "?" + sasToken
  print(url)
  </code></pre>
  
  <p>Any ideas how to fix this?  Thank you!</p>