HristoKolev / TvDbSharper

TvDbSharper is fully featured modern REST client for the TheTVDB API v4
MIT License
29 stars 17 forks source link

System.ArgumentException: Only 'http' and 'https' schemes are allowed. #7

Closed da3dsoul closed 7 years ago

da3dsoul commented 7 years ago

I can't tell if this is my fault or not. I can't imagine why the URL would have anything except http or https.

2017-07-17T20:36:14.151635931Z 20:36:14| --- Cache HTTP - Got AniDB/TvDB Cross Ref From Cache: 8181 - 550.758
2017-07-17T20:36:14.151925457Z 20:36:14| --- TvDBRateLimiter#32bdb11f-e79a-4c9e-91dd-5655ab0007cf: Time since last request is 1083589 ms, not throttling.
2017-07-17T20:36:14.153316267Z 20:36:14| --- Error in TvDBApiHelper.GetSeriesInfoOnline: System.ArgumentException: Only 'http' and 'https' schemes are allowed.
2017-07-17T20:36:14.153334036Z Parameter name: requestUri
2017-07-17T20:36:14.153342075Z   at System.Net.Http.HttpRequestMessage.InitializeValues (System.Net.Http.HttpMethod method, System.Uri requestUri) [0x00032] in <09d4a140061c48849b6322067e841931>:0 
2017-07-17T20:36:14.153348454Z   at System.Net.Http.HttpRequestMessage..ctor (System.Net.Http.HttpMethod method, System.Uri requestUri) [0x00049] in <09d4a140061c48849b6322067e841931>:0 
2017-07-17T20:36:14.153353892Z   at System.Net.Http.HttpClient.PostAsync (System.Uri requestUri, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) [0x00005] in <09d4a140061c48849b6322067e841931>:0 
2017-07-17T20:36:14.153359394Z   at System.Net.Http.HttpClient.PostAsync (System.String requestUri, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) [0x00008] in <09d4a140061c48849b6322067e841931>:0 
2017-07-17T20:36:14.15336448Z   at TvDbSharper.JsonClient.JsonClient+<PostJsonAsync>d__13`1[TResponse].MoveNext () [0x0003f] in <f3b46941f51d4f56aff938113cb69e1a>:0 
2017-07-17T20:36:14.153369599Z --- End of stack trace from previous location where exception was thrown ---
2017-07-17T20:36:14.153374209Z   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153411996Z   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153418094Z   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.15342334Z   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153428306Z   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <4dc8ec68b0964e099af86e50301f5f3c>:0  
2017-07-17T20:36:14.153433419Z   at TvDbSharper.Clients.Authentication.AuthenticationClient+<AuthenticateAsync>d__10.MoveNext () [0x0009c] in <f3b46941f51d4f56aff938113cb69e1a>:0 
2017-07-17T20:36:14.153438455Z --- End of stack trace from previous location where exception was thrown ---
2017-07-17T20:36:14.153442889Z   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153447816Z   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153452758Z   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153485853Z   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153493898Z   at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153499094Z   at Shoko.Server.Providers.TvDB.TvDBApiHelper+<_checkAuthorizationAsync>d__5.MoveNext () [0x00093] in <a7ae1973e8af49399181d79028d15a1b>:0 
2017-07-17T20:36:14.153505898Z --- End of stack trace from previous location where exception was thrown ---
2017-07-17T20:36:14.153510454Z   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153515275Z   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153520331Z   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153525505Z   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153530442Z   at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <4dc8ec68b0964e099af86e50301f5f3c>:0 
2017-07-17T20:36:14.153535281Z   at Shoko.Server.Providers.TvDB.TvDBApiHelper+<GetSeriesInfoOnlineAsync>d__7.MoveNext () [0x00085] in <a7ae1973e8af49399181d79028d15a1b>:0 
HristoKolev commented 7 years ago

Check the base url that you are using.

da3dsoul commented 7 years ago

That's why I'm confused. We don't pass any URL. This is the part that is caught.

    await CheckAuthorizationAsync();
    TvDBRateLimiter.Instance.EnsureRate(); // Lock to ensure we don't flood
    var response = await client.Series.GetAsync(seriesID);
    Series series = response.Data;

The auth is done as:

    client.AcceptedLanguage = ServerSettings.TvDB_Language;
    if (client.Authentication.Token == null)
    {
        TvDBRateLimiter.Instance.EnsureRate();
        await client.Authentication.AuthenticateAsync(Constants.TvDB.apiKey);
    }
HristoKolev commented 7 years ago

Does it do that with every request or with Series.Get only? When did this start to happen?

da3dsoul commented 7 years ago

I haven't found a pattern, it only happens sometimes. It's happened since we started using it, but we had bigger things to iron out, so we ignored it. I'll add more logging and catching to see if I can narrow it down, but thought I'd see if you knew about it.

HristoKolev commented 7 years ago

No, I had no idea. This is a big problem.

da3dsoul commented 7 years ago

Actually, upon second glance at the log, that's happening in Auth. Trimmed Log:

2017-07-17T20:36:14.153334036Z Parameter name: requestUri
2017-07-17T20:36:14.153342075Z   at System.Net.Http.HttpRequestMessage.InitializeValues (System.Net.Http.HttpMethod method, System.Uri requestUri) [0x00032] in <09d4a140061c48849b6322067e841931>:0 
2017-07-17T20:36:14.153348454Z   at System.Net.Http.HttpRequestMessage..ctor (System.Net.Http.HttpMethod method, System.Uri requestUri) [0x00049] in <09d4a140061c48849b6322067e841931>:0 
2017-07-17T20:36:14.153353892Z   at System.Net.Http.HttpClient.PostAsync (System.Uri requestUri, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) [0x00005] in <09d4a140061c48849b6322067e841931>:0 
2017-07-17T20:36:14.153359394Z   at System.Net.Http.HttpClient.PostAsync (System.String requestUri, System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) [0x00008] in <09d4a140061c48849b6322067e841931>:0 
2017-07-17T20:36:14.15336448Z   at TvDbSharper.JsonClient.JsonClient+<PostJsonAsync>d__13`1[TResponse].MoveNext () [0x0003f] in <f3b46941f51d4f56aff938113cb69e1a>:0 
2017-07-17T20:36:14.153369599Z --- End of stack trace from previous location where exception was thrown ---
--- Task Exception Catching ---
2017-07-17T20:36:14.153433419Z   at TvDbSharper.Clients.Authentication.AuthenticationClient+<AuthenticateAsync>d__10.MoveNext () [0x0009c] in <f3b46941f51d4f56aff938113cb69e1a>:0 
2017-07-17T20:36:14.153438455Z --- End of stack trace from previous location where exception was thrown ---
--- Task Exception Catching ---
2017-07-17T20:36:14.153499094Z   at Shoko.Server.Providers.TvDB.TvDBApiHelper+<_checkAuthorizationAsync>d__5.MoveNext () [0x00093] in <a7ae1973e8af49399181d79028d15a1b>:0 
2017-07-17T20:36:14.153505898Z --- End of stack trace from previous location where exception was thrown ---
--- Task Exception Catching ---
2017-07-17T20:36:14.153535281Z   at Shoko.Server.Providers.TvDB.TvDBApiHelper+<GetSeriesInfoOnlineAsync>d__7.MoveNext () [0x00085] in <a7ae1973e8af49399181d79028d15a1b>:0 
HristoKolev commented 7 years ago

Yes, yes. I saw it. On what platform are you running? Mono?

da3dsoul commented 7 years ago

Both Windows and Mono. Mono is alpha, and has its own network issues, though. This is produced in Windows 10.

HristoKolev commented 7 years ago

What version of .NET ?

da3dsoul commented 7 years ago

4.6.2, also tried with 4.7

HristoKolev commented 7 years ago

My code is very simple and does not do any funky stuff with the url, and if you are not messing with the base url...

The exception is thrown here:

 private void InitializeValues(HttpMethod method, Uri requestUri)
    {
      if (method == (HttpMethod) null)
        throw new ArgumentNullException("method");
      if (requestUri != (Uri) null && requestUri.IsAbsoluteUri && !HttpUtilities.IsHttpUri(requestUri))
        throw new ArgumentException(SR.net_http_client_http_baseaddress_required, "requestUri");
      this._method = method;
      this._requestUri = requestUri;
      this._version = HttpUtilities.DefaultRequestVersion;
    }

This is a part of the HttpRequestMessage class from System.Net.Http, I have no idea why it would throw at random like that.

I was thinking of moving from HttpClient to simple HttpWebRequest. I guess I will be doing that a little bit sooner.

da3dsoul commented 7 years ago

Odd. We've not had any issues with HTTPClient either, we use it for several things.

HristoKolev commented 7 years ago

Leave this open, it will be helpful to see if anyone else has this problem.

I will be investigating this, and possibly start the move to the older HttpWebRequest. It's not a big thing by itself, but in reality I have to rewrite all 300+ tests and I don't know when that will be happening. Maybe a week or two.

HristoKolev commented 7 years ago

I replaced the HttpClient as a part of the refactoring. A new version of the package is available with minor breaking changes.

da3dsoul commented 7 years ago

What are the breaking changes?

HristoKolev commented 7 years ago

Namespaces mostly. Removed a few. Exception handling. Nothing substantial.

da3dsoul commented 7 years ago

Mk