Azure-cosmos-dotnet-v2: Request headers must contain only ASCII characters.

Created on 21 Jul 2018  路  8Comments  路  Source: Azure/azure-cosmos-dotnet-v2

Hi!

I tested Microsoft.Azure.DocumentDB.Core 2.0.0-preview and got the exception below when executing: FeedResponse response = await query.ExecuteNextAsync();

System.Net.Http.HttpRequestException: Request headers must contain only ASCII characters.
at System.Net.Http.HttpConnection.WriteStringAsync(String s)
at System.Net.Http.HttpConnection.WriteHeadersAsync(HttpHeaders headers, String cookiesFromContainer)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.Azure.Documents.Client.DocumentClient.HttpRequestMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Microsoft.Azure.Documents.GatewayStoreModel.<>c__DisplayClass20_0.<<InvokeAsync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.Documents.BackoffRetryUtility1.<>c__DisplayClass1_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.Documents.BackoffRetryUtility1.ExecuteRetry(Func1 callbackMethod, Func3 callShouldRetry, Func1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action1 preRetryCallback) at Microsoft.Azure.Documents.BackoffRetryUtility1.ExecuteRetry(Func1 callbackMethod, Func3 callShouldRetry, Func1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action1 preRetryCallback)
at Microsoft.Azure.Documents.BackoffRetryUtility1.ExecuteAsync(Func1 callbackMethod, IRetryPolicy retryPolicy, CancellationToken cancellationToken, Action1 preRetryCallback) at Microsoft.Azure.Documents.GatewayStoreModel.InvokeAsync(DocumentServiceRequest request, ResourceType resourceType) at Microsoft.Azure.Documents.GatewayStoreModel.ProcessMessageAsync(DocumentServiceRequest request) at Microsoft.Azure.Documents.Client.DocumentClient.ExecuteQueryAsync(DocumentServiceRequest request) at Microsoft.Azure.Documents.Query.DocumentQueryClient.ExecuteQueryAsync(DocumentServiceRequest request) at Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase.ExecuteQueryRequestInternalAsync(DocumentServiceRequest request) at Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase.ExecuteQueryRequestAsync(DocumentServiceRequest request) at Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase.ExecuteRequestAsync(DocumentServiceRequest request) at Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext.ExecuteOnceAsync(IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken token) at Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext.<>c__DisplayClass9_0.<<ExecuteInternalAsync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.Documents.BackoffRetryUtility1.<>c__DisplayClass1_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.Documents.BackoffRetryUtility1.ExecuteRetry(Func1 callbackMethod, Func3 callShouldRetry, Func1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action1 preRetryCallback) at Microsoft.Azure.Documents.BackoffRetryUtility1.ExecuteRetry(Func1 callbackMethod, Func3 callShouldRetry, Func1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action1 preRetryCallback)
at Microsoft.Azure.Documents.BackoffRetryUtility1.ExecuteAsync(Func1 callbackMethod, IRetryPolicy retryPolicy, CancellationToken cancellationToken, Action1 preRetryCallback) at Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext.ExecuteInternalAsync(CancellationToken token) at Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase.ExecuteNextAsync(CancellationToken token) at Microsoft.Azure.Documents.Query.ProxyDocumentQueryExecutionContext.ExecuteNextAsync(CancellationToken token) at Microsoft.Azure.Documents.Linq.DocumentQuery1.ExecuteNextPrivateAsyncTResponse
at Myfavorite.Common.Repositories.CosmosDatabaseRepository.GetListByQueryT in D:\ASP-hemsidor\NetCoreApplications\Myfavorite\Myfavorite.Common\Repositories\CosmosDatabaseRepository.cs:line 398
at Myfavorite.Common.Repositories.LocationRepository.GetChunk(String sort_field, String sort_order, Int32 page_size, String ct) in D:\ASP-hemsidor\NetCoreApplications\Myfavorite\Myfavorite.Common\Repositories\LocationRepository.cs:line 270
at Myfavorite.Common.Repositories.QueueServices.GetLocations(Int32 page_size) in D:\ASP-hemsidor\NetCoreApplications\Myfavorite\Myfavorite.Common\Repositories\QueueServices.cs:line 56
at Myfavorite.Job.Repositories.WorkerRepository.AddAndUpdatePlaces() in D:\ASP-hemsidor\NetCoreApplications\Myfavorite\Myfavorite.Job\Repositories\WorkerRepository.cs:line 95

Most helpful comment

Same thing for me in Microsoft.WindowsAzure.Storage as well

All 8 comments

Hi!

I used an old continuation token that included "St枚de" as item. I did reset the continuation token to null and it started to work again. I will wait and see if item gets encoded in the new version of document db.

[{\"compositeToken\":{\"token\":\"+RID:s5EcAORqcgDcDAAAAAAAAA==#RT:3#TRC:60#RTD:mRdBbHZoZW0=#FPC:AgEAAACcANEMAPCBQA/wgkD/BwD/okD/AMAAEAASQA8AAP8SQP8PAICkQAcA4P//AAD8kkB/AADwEkD/AwD/IEARAID/YkD/APj/QUEDABAAYkD/AwD+ZkB/APj//w8A4B8AAPyDQB8AAP8PgFJAfwDA/yJA//7/vxFA+/8yQO//7/8RQL//EUDv/yFA/wABBvz/EUL/wzFB5/9BQAMAAUf/Bw==\",\"range\":{\"min\":\"\",\"max\":\"FF\"}},\"orderByItems\":[{\"item\":\"St枚de\"}],\"rid\":\"s5EcAORqcgDcDAAAAAAAAA==\",\"skipCount\":0,\"filter\":\"true\"}]

Hi,

the problem still persists. I encountered a continuation token with UTF-8 characters today and it failed with the exception above. The item is "L盲cker - Ola Arena".

[{"compositeToken":{"token":"+RID:s5EcAORqcgBVZwAAAAAAAA==#RT:1#TRC:10#RTD:AqoiIEzDpGNrZXIgLSBPbGEgQXJlbmEgIg==#FPC:AgEAPQAGAGEnAPiQWAECAABAAgIAAEADAgAAQAQCAABABQIAAEAGAgAAQAcCAABACAIAAEAJBgBBaf/3sFYKAgAAQAsGAFFG/4+geQwCAABADQIAAEAOCgBhfh8AEQD4/3BBDwIAAEAQAgAAQBECAABAEgIAAEATAgAAQBQCAABAFQIAAEAWAgAAQBcCAABAGAIAAEAZAgAAQBoCAABAGwoA0Vnf/2Fd/++wSBwCAABAHQIAAEAeAgAAQB8GAGFc/3+QYyACAABAIQoAEV7/ASEA+P+wYSICAABAIwIAAEAkAgAAQCUCAABAJgIAAEAnBgDBQP7/MH8oAgAAQCkCAABAKgIAAEArAgAAQCwCAABALQYAgUXf/3B6LgIAAEAvAgAAQDAGAJFD//dgfDECAABAMgIAAEAzBgCxZt//QFk0BgCRav/9YFU1AgAAQDYCAABANwIAAEA4AgAAQDkCAABAOgIAAEA7AgAAQDwGAJFR/v9gbj0YAJFd9/9hTf/3QUD7/9JIf/+D//JB//0/AA==","range":{"min":"","max":"FF"}},"orderByItems":[{"item":"" L盲cker - Ola Arena ""}],"rid":"s5EcAORqcgBVZwAAAAAAAA==","skipCount":0,"filter":null}]

The problem is that I have this problem on Azure even if I use Microsoft.Azure.DocumentDB.Core 1.9.1. It works on localhost with Microsoft.Azure.DocumentDB.Core 1.9.1.

A workaround is order by parameters that only contains ASCII characters.

Hi,
Just wanted to add in here I'm having the same issue.

Hi,
I have the exact same issue using Microsoft.Azure.DocumentDB.Core 2.4.0.

same issue

Same thing for me in Microsoft.WindowsAzure.Storage as well

same issue here. Any solution except avoid order by name?

Don't know if it can help, I fixed this error in my dotnet code using the following procedure :

For those who came accross this post for trying to send not extended ascii characters (as french accents, chinese characters etc...), here is a resume :

Modify your httpclient headers set from :
client.DefaultRequestHeaders.Add("YOUR_HTTP_HEADER", "yourv脿luewithsp茅cialcharacters");

To :
client.DefaultRequestHeaders.Add("YOUR_HTTP_HEADER", Convert.ToBase64String(Encoding.UTF8.GetBytes("yourv脿luewithsp茅cialcharacters")));

In my case it worked and fixed the HttpRequestException : _Request headers must contain only ASCII characters._
Thanks to @Jizhangben

Was this page helpful?
0 / 5 - 0 ratings