Trying to download Excel (*.xlsx) files from Google Drive.
When calling DriveService.HttpClient.GetByteArrayAsync() I get this error:
System.Net.Http.HttpRequestException Response status code does not indicate success: 500 (Internal Server Error
- This error happens randomly
- The Excel files range in size from 0.5 MB to 15 MB
- One file does seem to error more frequently. It is 4 MB
- This happened randomly every month or so. Starting this week it happens nearly every time I run code that downloads 18 Excel files.
I created a catch/retry mechanism which seems to work with 3 attempts. I still would like a fix
byte[] byteArray = Encoding.UTF8.GetBytes(map.Credentials);
string[] scopes = new string[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile };
UserCredential credential;
using (var stream = new MemoryStream(byteArray))
{
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
DriveService driveService = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
string path = "https://www.googleapis.com/drive/v3/files/" + map.Path + "?alt=media";
var x = driveService.HttpClient.GetByteArrayAsync(path);
byte[] arrBytes = x.Result; // Randomly throws exception