Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

401 Unauthorized when downloading multiple files

Discussion in 'Unity Cloud Content Delivery' started by alexanderameye, Feb 17, 2021.

  1. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,312
    Basically I'm trying to download multiple files, one after another. It does kind of seem to work, but it's not very consistent. Sometimes all requested files are downloaded, sometimes only a few, sometimes none.

    When the file doesn't get downloaded, I get a 401 unauthorized error even though I have set the authentication header correctly.

    Here is the code I'm using.

    Code (CSharp):
    1. IEnumerator DownloadContent(string bucket, string entry, string downloadPath)
    2.     {
    3.  
    4.         // string requestURL = UCDHelper.ManagementAPI + "/buckets/" + bucket + "/entries/" + entry + "/content/";
    5.         string requestURL = UCDHelper.ManagementAPI + "/buckets/" + bucket + "/entries/" + entry + "/content/";
    6.  
    7.         Debug.Log("Get Content For Entry: " + requestURL);
    8.         using (UnityWebRequest request = UnityWebRequest.Get(requestURL))
    9.         {
    10.             request.downloadHandler = new DownloadHandlerFile(downloadPath);
    11.            // request.SetRequestHeader("accept", "application/octet-stream");
    12.             request.SetRequestHeader("Authorization", "Basic " + UCDHelper.GetAuthenticationKey());
    13.      
    14.             yield return request.SendWebRequest();
    15.  
    16.             if (request.isHttpError || request.isNetworkError)
    17.             {
    18.                 Logger.LogError("GET BUCKET ENTRIES REQUEST FAILED", request.error + " [" + request.responseCode + "]");
    19.                 Logger.InterpretHTTPError(request.responseCode);
    20.             }
    21.  
    22.             else
    23.             {
    24.                 Logger.LogSuccess("FILE DOWNLOADED", Path.GetFileName(downloadPath));
    25.          
    26.                 // create an entry for the downloaded content
    27.                 // since the content has just been downloaded, it is synced
    28.                 AddContentEntry(downloadPath, ContentState.Synced);
    29.             }
    30.         }
    31.     }
    @timtunity3d any idea what might be happening? Is it possible that my requests are interfering with one another and causing the response to be unauthorized? Should I wait between downloads?
     
    Last edited: Feb 17, 2021
  2. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,312
    For what it's worth, just for testing I also tried your code for downloading multiple files @jpgordon00 and just manually set the URLs. Same result, only 2/4 files get downloaded. The other 2 get a 401 unauthorized. I also tried to put a delay of like 5 seconds between 2 download requests, but no difference.

    Does this maybe have something to do with releases? Do files need to be part of a release in order to be downloaded? Both using management/client API?

    With some further tests I think that it's always the same files that get (not) downloaded. What could be causing that?

    Also, the API docs speak about these error codes.

    Code (CSharp):
    1. 0 - OK
    2. 1 - Invalid argument
    3. 2 - Out of range
    4. 3 - Unauthenticated
    5. 4 - Permission denied
    6. 5 - Not found
    7. 6 - Already exists
    8. 7 - Unknown error
    9. 8 - Internal error
    10. 9 - Invalid operation
    11. 10 - Organization Activation is needed
    12. 11 - operation cannot be completed due to an incomplete upload
    13. 12 - too many requests
    How do I get these?

    The response I get is like this.

    Code (CSharp):
    1. <?xml version='1.0' encoding='UTF-8'?><Error><Code>AuthenticationRequired</Code><Message>Authentication required.</Message></Error>
     
    Last edited: Feb 17, 2021
  3. timtunity3d

    timtunity3d

    Unity Technologies

    Joined:
    Oct 1, 2015
    Posts:
    86
    Hi,

    Could you try again today and let us know how it goes? Some of our errors yesterday were caused by an issue with Unity’s core authentication service. This affected the dashboard, CLI, and management API requests. Client requests should have been unaffected. We’re currently looking at ways to limit our reliance to increase our resilience to any outages there
     
  4. jpgordon00

    jpgordon00

    Joined:
    Jan 9, 2021
    Posts:
    10
    Do your requests need any special headers set? Have you tried the same URI's to ensure they are accessible from at least your desktop?

    Not sure why UnityWebRequest would fail if the URI is accessible publicly.
     
unityunity