Google Drive Api - Error after copying multiple files .NET - Cancel connection by remote host

一个人想着一个人 提交于 2020-06-17 14:20:08

问题


Console application below return exception after copying many files. I'd like to know the exactly limit of copying and creating folders with Google drive api in .NET. Follow the Inner Exception: "Unable to read data from the transport connection: Was Forced to cancel the exist connection by remote host".

static void Main(string[] args)
    {
        if (Debugger.IsAttached)
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US");
        string[] Scopes = { DriveService.Scope.DriveReadonly, DriveService.Scope.DriveFile };            
        ServiceAccountCredential credential;                                    
        using (var stream =
                        new FileStream("key.json", FileMode.Open, FileAccess.Read))
        {                            
            credential = GoogleCredential.FromStream(stream)
                                 .CreateScoped(Scopes)
                                 .UnderlyingCredential as ServiceAccountCredential;                
        }
        // Create Drive API service.
        var service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Test App",
        });            
        Google.Apis.Drive.v3.Data.File copiedFile = new Google.Apis.Drive.v3.Data.File();
        for (int i = 0; i < 50; i++)
        {                
            copiedFile.Name = "";                
            copiedFile.Parents = new List<string> { "1I6eCYECR8lfpWP6wFDWeYkTsUMC6jKie" };                 
            try
            {
                var lFile = service.Files.Copy(copiedFile, "157cV64pH6Jdpm8SER1MQStPhnl01XHI65AsfPwSeTqw").Execute();
                Console.WriteLine("File " + (i+1).ToString() + " copied.");
            }
            catch (Exception e)
            {                    
                Console.WriteLine("Error = " + e.InnerException.Message);
            }
        }                     
    }

Print_Error


回答1:


Thanks for helping! I've realized that our SonicWall firewall was blocking some requests. After set (Sonicwall) to not block our request, the issue was resolved. I have attached the full error here.

Print Error



来源:https://stackoverflow.com/questions/62161904/google-drive-api-error-after-copying-multiple-files-net-cancel-connection-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!