【问题标题】:How to troubleshoot "Value cannot be null. Parameter name: baseUri"如何解决“值不能为空。参数名称:baseUri”
【发布时间】:2015-11-03 15:56:46
【问题描述】:

我需要帮助来诊断此错误。其他人在各种平台(例如 youtube)上获得它,但对于大多数人来说似乎没有解决。对于那些报告成功的人来说,他们的解决方案对我不起作用。

我正在使用 Google Drive API,但在尝试上传到 Google Drive 时收到此错误。

我的代码在很长一段时间内都运行良好;突然,我得到这个错误。经过研究,我确定我没有达到配额,并且启用了这些 API:

  • 调试控制器 API
  • 驱动 API
  • 谷歌云数据流 API
  • Google Cloud Dataproc API
  • 谷歌云部署管理器 API
  • 谷歌云部署管理器 V2 API
  • 谷歌云存储
  • 谷歌云存储 JSON API
  • Google 计算引擎自动扩缩器 API
  • Google Compute Engine 实例组管理器 API
  • Google Compute Engine 实例组更新程序 API
  • Google 计算引擎实例组 API
  • Google 容器引擎 API
  • Google 机器学习 API

这是我的代码:

        string fileName = @"c:\temp\MyPicture.jpg";
        string fileTitle = @"TEST-DELETE-ME.jpg";
        string fileDescription = @"Test file name";
        string fileType = "image/jpeg";
        string parentId = "zmzmzmzmzmzmzmzmzmz";

        Google.Apis.Drive.v2.DriveService service = (Google.Apis.Drive.v2.DriveService)Service;

        Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
        body.Title = fileTitle;
        body.Description = fileDescription;
        body.MimeType = fileType;
        body.Parents = new List<ParentReference> { new ParentReference() { Id = parentId } };

        byte[] byteArray = System.IO.File.ReadAllBytes(fileName);

        System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

        Google.Apis.Drive.v2.FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, fileType);

        Google.Apis.Upload.IUploadProgress progress = request.Upload();

        Google.Apis.Drive.v2.Data.File file = request.ResponseBody;

        if (file == null)
        {
            //Here we are, and we shouldn't be!
            //progress.exception.message = 
            //
            //Value cannot be null.
            //Parameter name: baseUri
        }

当我查看 Drive API 设置时,这些是配置:

  • 无图标(有框设置256x265、128x128、64x64、32x32、16x16都是空白)

  • 应用程序名称和短描述和长描述都是空白和可选的。

  • 对于 Drive Integration,所有框和复选框均为空白或未选中。具体来说:

  • “自动显示 OAuth 2.0 同意...”未选中。

  • “打开 URL”为空白。

  • 默认和次要 MIME 类型和文件扩展名是空白的

  • “允许用户创建新文档...”未选中

  • “允许用户打开多个文件...”未选中

  • “允许用户打开可转换的文件...”未选中

  • 未选中“此应用程序可以在移动浏览器中启动并正常运行”。

用户不使用 Google Drive UI 通过我的应用程序创建文档,并且不打算在移动浏览器上使用。我的应用程序仅将 PDF 文件上传到用户的帐户。

我的应用程序已经运行了几个月没有任何问题,现在突然看到这个错误。

我已尝试禁用所有 API,然后重新启用它们。没有骰子。

我尝试使用新的客户端 ID 和密码。没有骰子。

我尝试使用新的 gmail 地址并创建新的客户端 ID 和密码。没有骰子。

我不可能是世界上唯一遇到这个问题的人。谁能帮我解决这个问题?

【问题讨论】:

  • 我也在使用这个库,但用于谷歌云存储。我遇到了两个(迄今为止)导致此模棱两可的错误消息的异常情况。如果客户端未正确验证,并且我尝试上传 blob,则会收到此“baseUri”异常。如果我尝试上传到不存在的存储桶,我会收到此“baseUri”异常。您可能正在为 google drive 执行类似的操作(不确定 Drive 的等效情况是什么,但肯定存在。)但是,我确实在尝试检索 blob 时收到了正确的错误消息...
  • 感谢 Anj 的反馈。就我而言,我的代码允许登录、导航文件夹以及上传或下载文件。下载工作正常,是上传失败。因此该文件夹存在并且身份验证有效。我应该提到代码没有改变,尽管代码曾经工作过。这就是为什么我提供了我所做的细节;有人建议我的 API 权限配置不正确。
  • 添加了 Google-Cloud-Platform 标签,希望能够扩大与其他开发者的联系。
  • 该错误看起来是由 .NET 客户端本身生成的,而不是 Drive API 生成的。请包含完整的堆栈跟踪。
  • 感谢 Stack Trace: 在 Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) 在 Microsoft.Runtime.CompilerServices 的回复。 TaskAwaiter.ValidateEnd(任务任务)在 Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Upload.ResumableUpload1.d__e.MoveNext() 在 c:\code\github\google-api-dotnet-client\Tools\Google.Apis。 Release\bin\Release\1.9.2\default\Src\GoogleApis\Apis[Media]\Upload\ResumableUpload.cs:460行

标签: google-app-engine google-drive-api google-cloud-platform google-api-dotnet-client


【解决方案1】:

潜在问题类似于授权问题或请求的其他错误。但是,.NET 客户端中存在一个隐藏错误的错误。

https://github.com/google/google-api-dotnet-client/issues/456

【讨论】:

  • 根据要求,我提供了上面的堆栈跟踪。对不起,我不知道如何在这个论坛中格式化它,所以它不能很好地显示出来。我应该提到我没有收到运行时错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-16
相关资源
最近更新 更多