Azure / azure-cosmos-dotnet-v2

Contains samples and utilities relating to the Azure Cosmos DB .NET SDK
MIT License
577 stars 838 forks source link

Request headers must contain only ASCII characters. #552

Open fredrik-stigsson opened 6 years ago

fredrik-stigsson commented 6 years ago

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.<>cDisplayClass1_0.<b0>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, Action`1 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.<>cDisplayClass9_0.<b0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.Documents.BackoffRetryUtility1.<>c__DisplayClass1_0.<<ExecuteAsync>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.DocumentQuery`1.ExecuteNextPrivateAsync[TResponse](CancellationToken token) at Myfavorite.Common.Repositories.CosmosDatabaseRepository.GetListByQuery[T](String sql, SqlParameterCollection parameters, Int32 page_size, String ct) 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

fredrik-stigsson commented 6 years ago

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\"}]

fredrik-stigsson commented 6 years ago

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.

jsneedles commented 5 years ago

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

jezeri commented 5 years ago

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

irriss commented 5 years ago

same issue

TanmayDharmaraj commented 5 years ago

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

xiaohu0828 commented 5 years ago

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

ysris commented 5 years ago

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