【问题标题】:Node.js Azure File Service - 403 Error DebuggingNode.js Azure 文件服务 - 403 错误调试
【发布时间】:2017-04-05 21:25:59
【问题描述】:

我目前在尝试使用 Azure 的 Node.js SDK 时遇到 403 错误。当我直接调用它时,下面的函数可以完美运行:

module.exports = function (file, callback) {
  if (!fs.existsSync('./data')) {
    mkdirp('./data', function (err) {
      if (err) console.log(err)
    })
  }
  fileService.getFileToStream('chatbot', '', file, fs.createWriteStream('data/' + file), function (err, res, response) {
    if (!err) {
      fs.readFile('data/' + file, 'utf8', function (err, data) {
        if (!err) {
          callback(null, data)
        } else {
          callback(err)
        }
      })
    } else {
      callback(err)
    }
  })
}

但是,当我从更广泛的应用程序中调用它时,我会收到 403 错误:

{ StorageError: Forbidden
    at Function.StorageServiceClient._normalizeError (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/lib/common/services/storageserviceclient.js:1174:23)
    at FileService.StorageServiceClient._processResponse (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/lib/common/services/storageserviceclient.js:729:50)
    at Request.processResponseCallback [as _callback] (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/lib/common/services/storageserviceclient.js:310:37)
    at Request.self.callback (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/node_modules/request/request.js:187:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/node_modules/request/request.js:1044:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/node_modules/request/request.js:965:12)
  name: 'StorageError',
  message: 'Forbidden',
  code: 'Forbidden',
  statusCode: 403,
  requestId: '51ce6605-001a-00c1-1d52-ae966b000000' }

问题在于,除了 403 错误之外,我似乎无法对此进行调试。由于代码完全独立运行,因此我知道访问密钥不是问题。 Azure 存储允许您记录表、Blob 和队列的访问数据,但不能记录文件服务,这似乎令人难以置信 (https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/enabling-storage-logging-and-accessing-log-data#HowtoenableStorageLoggingusingtheWindowsAzureManagementPortal)。

有人对如何进一步调试有任何想法吗?

【问题讨论】:

    标签: node.js azure azure-storage-files


    【解决方案1】:

    您可以在两者之间放置一个调试代理,例如 mitmproxyFiddlerCharles,以查看请求和响应之间的区别。

    NODE_TLS_REJECT_UNAUTHORIZED=0 HTTP_PROXY=http://127.0.0.1:8888 node app.js
    

    【讨论】:

      【解决方案2】:

      有一个issue in the ApplicationInsights package 会导致来自存储的 403 响应。此问题已在 0.18.0 版本中修复。

      【讨论】:

      • 谢谢!我使用的是 ApplicationInsights (0.19) 的最新版本,但是当我注释掉与 ApplicationInsights 相关的所有内容时,该应用程序运行良好。我会看一下,可能会在 ApplicationInsights 存储库上提出一个问题。
      猜你喜欢
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 2011-08-27
      相关资源
      最近更新 更多