Azure table storage returns 400 Bad Request

I ran this in debug mode and I am attaching an image with exception details. How can I find out what went wrong? I tried to insert data into a table. Can't get more details?

Observation: The repository is not on my machine on Windows Azure. Tables have been created, but I get this error when inserting data

enter image description here

// Retrieve the storage account from the connection string. Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***"); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Create the table if it doesn't exist. CloudTable table = tableClient.GetTableReference("EmployeeOnlineHistory"); table.CreateIfNotExists(); 

and here is the insert code:

 public static void SetStatus(Employee e, bool value) { try { // Retrieve the storage account from the connection string. Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=###;AccountKey=###"); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table = tableClient.GetTableReference("EmployeeOnlineHistory"); // Create a new customer entity. if (value == true) { EmployeeOnlineHistory empHistory = new EmployeeOnlineHistory(e.Id); empHistory.IsOnline = true; empHistory.OnlineTimestamp = DateTime.Now; TableOperation insertOperation = TableOperation.Insert(empHistory); table.Execute(insertOperation); } else { TableQuery<EmployeeOnlineHistory> query = new TableQuery<EmployeeOnlineHistory>() .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, e.Id.ToString())); EmployeeOnlineHistory entity = table.ExecuteQuery(query).Take(1).FirstOrDefault(); if ((entity!=null)&&(entity.IsOnline)) { entity.IsOnline = false; entity.OfflineTimestamp = DateTime.Now; entity.OnlineTime = (entity.OfflineTimestamp - entity.OnlineTimestamp); TableOperation updateOperation = TableOperation.Replace(entity); table.Execute(updateOperation); } else { EmployeeOnlineHistory empHistory = new EmployeeOnlineHistory(e.Id); empHistory.IsOnline = false; empHistory.OfflineTimestamp = DateTime.Now; TableOperation insertOperation = TableOperation.Insert(empHistory); table.Execute(insertOperation); } } } catch (Exception ex) { //var details = new System.IO.StreamReader(((Microsoft.WindowsAzure.Storage.StorageException)ex)..Response.GetResponseStream()).ReadToEnd(); LogFile.Error("EmployeeOnlineHistory.setStatus",ex); } } 
+111
c # exception azure azure-table-storage
Feb 13 '13 at 17:30
source share
19 answers

400 Error means that something is wrong with the value of one of your properties. One way to find out is to track the request / response through Fiddler and see the actual data sent to Windows Azure Storage.

Accepting wild assumptions, I assume by looking quickly at your code that in your model you have properties of type Date / Time (OfflineTimestamp, OnlineTimestamp), and noticed that in certain scenarios one of them initializes to the default value, which is " DateTime. MinValue ". Note that the minimum value allowed for an attribute of type Date / Time is January 1, 1601 (UTC) on Windows Azure [http://msdn.microsoft.com/en-us/library/windowsazure/dd179338.aspx] . Please take a look, right. If so, then you can make them fields with a null type so that they are not populated with default values.

Take a look at Juha Palomäki's answer below, and also ... there is sometimes a slightly more useful message in the exception where it suggests (RequestInformation.ExtendedErrorInformation.ErrorMessage)

+132
Feb 14 '13 at 2:29
source share

StorageException also contains a bit more detailed error information.

Debug Check: StorageException.RequestInformation.ExtendedInformation

enter image description here

+114
Aug 20 '14 at 8:57
source share

In my case, it was a slash in RowKey .

I also got "OutOfRangeInput" - one of the request input is out of range. when trying to add manually through the storage emulator.

Symbols prohibited in key fields

The following characters are not valid for values ​​for PartitionKey and RowKey :

  • Forward slash character ( / )
  • Backslash Character ( \ )
  • Number Symbol ( # )
  • Question mark symbol ( ? )
  • Control characters from U + 0000 to U + 001F , including:
    • Horizontal tab character ( \ t )
    • Linefeed character ( \ n )
    • Carriage Return Character ( \ r )
    • Control characters from U + 007F to U + 009F

http://msdn.microsoft.com/en-us/library/dd179338.aspx

I wrote an extension method to handle this for me.

 public static string ToAzureKeyString(this string str) { var sb = new StringBuilder(); foreach (var c in str .Where(c => c != '/' && c != '\\' && c != '#' && c != '/' && c != '?' && !char.IsControl(c))) sb.Append(c); return sb.ToString(); } 
+47
Mar 14 '14 at 18:05
source share

well, in my case, I tried to do this:

 CloudBlobContainer container = blobClient.GetContainerReference("SessionMaterials"); await container.CreateIfNotExistsAsync(); 

due to ContainerName SessionMaterials (like the habit of writing in the Pascal Case and Camel Case: D) it caused 400 invalid requests. So, I just have to do this sessionmaterials . and it worked.

Hope this helps someone.

PS: - Just check the http response exception or use fiddler to capture the request and response.

+5
May 24 '18 at 8:10
source share

I ran into the same problem, but the reason in my case was related to size. After searching for additional exception properties (RequestInformation.ExtendedErrorInformation), it turned out that:

ErrorCode: PropertyValueTooLarge ErrorMessage: The value of the property exceeds the maximum size (64 KB). If the property value is a string, then UTF-16 is encoded, and the maximum number of characters must be 32 KB or less.

+4
Jun 10 '16 at 20:21
source share

Sometimes this is because your partitionKey or rowKey is NULL

(this was the case for me)

+3
Jun 07 '16 at 13:07 on
source share

in my case: The name of the container was written in capital letters. there are restrictions when using characters. enter image description here

+3
Aug 24 '17 at 20:06 on
source share

MS documentation on all table service error codes can be found here.

+1
Jun 12 '17 at 9:35 on
source share

I had the same BadRequest (400) error, at the end I fill in manually:

enter image description here

And he worked for me. Hope this helps!

+1
Jun 15 '18 at 7:26
source share

I also faced the same problem. In my case, the PartitionKey was not set, so the default value of PartitionKey was null, which led to Object reference not set to an instance of an object. exception

Make sure you provide the appropriate values ​​for PartitionKey or RowKey, you may encounter such a problem.

0
Sep 01 '15 at 19:45
source share

I fixed my affairs and it worked great

My cases:

  • The line string is not in the correct format (400).
  • The combination of section and row keys is not unique (409).
0
Jul 12 '16 at 10:23
source share

I received 400 Bad Request because I used ZRS (backup zone storage), and Google Analytics is not available for this type of storage. I did not know that I was using Google Analytics.

I removed the storage container and recreated it as GRS, and now it works fine.

0
Nov 06 '16 at 6:07
source share

I received (400) an invalid request, StatusMessage: invalid request, ErrorCode: OutOfRangeInput when the object had the DateTime property not set (= DateTime.MinValue)

0
Feb 06 '18 at 8:26
source share

In my case: I included blob metadata with a tag name containing a hyphen.

 var blob = container.GetBlockBlobReference(filename); blob.Metadata.Add("added-by", Environment.UserName); //.. other metadata blob.UploadFromStream(filestream); 

The problem was "added-by" , and later, RTFM told me that tag names must follow C # identifier conventions.

Link: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-properties-metadata

Underline works fine.

0
Jul 29 '18 at 21:24
source share

In my case, I should not add PartitionKey and Rowkey to my entity class. This should be from the base class. Below will just work.

 public class TableRunLogMessage:TableEntity { public string status { get; set; } public long logged { get; set; } public TableRunLogMessage() { } } 
0
Nov 28 '18 at 19:31
source share

If you use NodeJS and stumbled upon this post, you will find that you will not receive this excellent detailed information in your error object; You can use proxies to get these details. However, since no one here mentions HOW to use a proxy.

The easiest way with NodeJS is to set two environment variables:

 NODE_TLS_REJECT_UNAUTHORIZED=0 This disables SSL checks so you can intercept your own SSL requests. This leaves you open to Man-in-The-Middle attacks and should NEVER make it to production, and I wouldn't even leave it in development for long. However, it will allow you to intercept the HTTP Requests. HTTP_PROXY=http://127.0.0.1:8888 This sets node to utilize a proxy listening on your localhost at port 8888. Port 8888 is the default for Fiddler. Many other proxies default to 8080. 

If you are actually using C #, as the author of this post does; You can simply install Fiddler and set it to intercept. By default, it should intercept requests. You may also need to trust the Fiddler certificate or otherwise make the equivalent of the node "NODE_TLS_REJECT_UNAUTHORIZED = 0".

0
Jan 08 '19 at 18:05
source share

I got a 400-BadRequest response from the Azure Storage Account Table API. Exclusion information indicated that "Account Access does not support http." I thought that we should use https in the connection string when “Secure Transfer Required” is enabled in the storage account configuration, as shown in the figure below. enter image description here

0
Apr 12 '19 at 23:43 on
source share

In my case, to create a new installation of the "TableBotDataStore" class (MS bot environment) we pass the "tableName" parameter with a hyphen, for example, "master-bot", and the TableBotDataStore can only have table names with letters and numbers

0
Jun 27 '19 at 9:33 am
source share

I had the same problem, the function passed containerNameKey as a string. below is the error code

 container = blobClient.GetContainerReference(containerNameKey) 

I changed it to

 container = blobClient.GetContainerReference(ConfigurationManager.AppSettings(containerNameKey).ToString()) 

It worked

0
Aug 20 '19 at 20:09 on
source share



All Articles