【问题标题】:Cannot access API explorer on localhost无法访问本地主机上的 API 资源管理器
【发布时间】:2013-07-16 09:33:57
【问题描述】:

我正在尝试构建一个 Endpoints 应用程序,但我是 Google App Engine 的新手。

据我了解,SDK 中包含某种 API Explorer,可以让我测试/验证我的 API——文档说:“通过导航到 http://localhost:8080/_ah/api/explorer 在 Google APIs Explorer 中测试 API 后端” .但我找不到任何关于 API Explorer 实际是什么、做什么或看起来像什么的文档。

无论如何,当我尝试访问该 URL 时,我会立即被重定向到 https://developers.google.com/apis-explorer/?base=http://localhost:8080/_ah/api#p/,这告诉我没有任何用处,而且似乎一定是某种错误。

devappserver 日志说:

INFO     2013-07-17 17:27:54,574 server.py:593] default: "GET /_ah/api/explorer HTTP/1.1" 302 -
INFO     2013-07-17 17:27:56,099 server.py:593] default: "GET /_ah/api/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.7JUwNUXMAS8.O%2Fm%3D__features__%2Fam%3DEQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAItRSTO0dpKS_pssf5r3z87E6FlFvDGdOg HTTP/1.1" 200 1933
INFO     2013-07-17 17:27:56,193 server.py:593] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 2342
INFO     2013-07-17 17:27:56,492 server.py:593] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 200 576
INFO     2013-07-17 17:27:56,507 server.py:593] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 2342
INFO     2013-07-17 17:27:56,583 server.py:593] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 2342
INFO     2013-07-17 17:27:56,811 server.py:593] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 200 576
INFO     2013-07-17 17:27:56,886 server.py:593] default: "GET /_ah/api/discovery/v1/apis/scrnxSync/v1/rest HTTP/1.1" 200 3365

不惜一切代价。

这是我的 app.yaml:

application: scrnx-cloud-1
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /admin/.*
  script: admin.application
  login: admin
  secure: always

  # Endpoints handler
- url: /_ah/spi/.*
  script: sync_api.application

  # catchall - must come last    
- url: /.*
  script: default.application


admin_console:
  pages:
  - name: View Measurement
    url: /admin/measurement  


libraries:
- name: jinja2
  version: 2.6
- name: markupsafe
  version: 0.15

builtins:
- admin_redirect: off
- appstats: off
- deferred: off
- remote_api: on

我还应该做些什么来设置它吗?

【问题讨论】:

    标签: google-app-engine google-cloud-endpoints


    【解决方案1】:

    发生了一些变化,现在您必须以特定方式启动 Chrome 才能在 localhost 开发服务器上使用 api explorer

    这里是link 来自 google 的信息。

    但对我来说,使用 api explorer 和 localhost 开发服务器仍然无法解决问题。
    我发现一种可能的解决方法是启动带有“--allow-running-insecure-content”标志的Chrome
    在终端中的 MacO 上运行:

    /Applications/Google\ Chrome.app/Contents/Mac/Google\ Chrome --user-data-dir=test --allow-running-insecure-content

    【讨论】:

      【解决方案2】:

      如果您使用的是 Chrome 浏览器,只需将 URL 中的 https 设置为 http。它对我有用。

      http://apis-explorer.appspot.com/apis-explorer/?base=http://localhost:8080/_ah/api#p/

      【讨论】:

      • 是url中的https还是url参数中的https?两者都有 http。
      【解决方案3】:

      API Explorer 的 URL 是正确的,但有一些问题(显然不是全部解决)API Explorer 没有正确列出您的 API。

      https://developers.google.com/apis-explorer/ 的外观相比,它是 Google API 的 API Explorer,其 API 比您通常自己托管的要多得多,但只是为了让您了解应该看到的内容:API 列表和点击后每个 API 的详细信息。

      通常可行的解决方法是将 API 的名称和版本显式添加到 URL,因此,由于您的 API 被称为 scrnxSync,版本为 v1,此链接应显示您为 API 定义的方法,并允许您调用这些方法:

      https://developers.google.com/apis-explorer/?base=http://localhost:8080/_ah/api#p/scrnxSync/v1/

      【讨论】:

      • 该链接对我有用(但使用端口 8888 和我的 API 名称)。为什么 localhost:8888/_ahi/api 不重定向我?它只是给了我 404。我只使用 GPE 从我的端点类生成端点库。工作正常部署到 GAE。直接关闭应用商店网址的资源管理器对我有用。
      【解决方案4】:

      我在 chrome 中尝试了以上所有方法,但对我来说没有任何效果,但是使用 Firefox 我只需单击 url 栏左侧的锁并禁用安全性。这对我来说是个窍门,干杯! :D

      【讨论】:

      • 感谢您的提示!这终于让这对我有用了。
      【解决方案5】:

      快速修复: 在 firefox 中打开链接:http://apis-explorer.appspot.com/apis-explorer/?base=http://localhost:8080/_ah/api#p/,然后单击导航栏上的安全连接图标,然后单击禁用保护。您应该能够看到您的 API

      ps;记得用你的端口号编辑 8080

      【讨论】:

        【解决方案6】:

        我也是 GAE Endpoints 的新手,遇到了同样的问题。 就我而言,由于 app.yaml 中 url 处理程序的顺序,我遇到了这个错误。我是这样的:

        - url: /.*
          script: core_service.application
        
          # Endpoints handler
        - url: /_ah/spi/.*
          script: api_service.application
        

        正确的方法是首先定义最具体的路由,最后定义最通用的 (/.*)。像这样:

          # Endpoints handler
        - url: /_ah/spi/.*
          script: api_service.application
        
        - url: /.*
          script: core_service.application
        

        【讨论】:

        • 我已经在阳光下尝试了一切,这很有效,谢谢伙计,这并使用 Firefox 单击 URL 栏左侧的锁解锁安全性。
        【解决方案7】:

        我知道这不是完全相同的问题,但我收到消息“您正在探索通过 HTTP 而不是 HTTPS 描述或提供的 API。这是不安全的,可能会被您的浏览器阻止。要解决此问题, "

        点击Chrome地址栏中的盾牌图标为我做到了。

        【讨论】:

        • 在 chrome 和 chromium 中都为我工作。
        【解决方案8】:

        如果您从 GWT DevMode 运行 AppEngine,您需要更改基本参数中的端口以匹配您在控制台中看到的内容,对我来说是 8888:

        http://apis-explorer.appspot.com/apis-explorer/?base=http://localhost:8888/_ah/api#p/

        【讨论】:

          【解决方案9】:

          对我来说,这是 app.yaml 中的一个非常简单的错字。如果你也有同样的问题,就这么简单:

          而不是(这是正确的):

          - url: /_ah/spi/.*
            script: services.application
          

          我说:

          - url: /_ah/api/.*
            script: services.application
          

          api 改回 spi 就行了。

          【讨论】:

          • 这不是错字。来自docsNote: In the following table on backend configuration and deployment issues, we refer to the path /_ah/spi, which you might think is a typo, because applications send their requests to /_ah/api. However, the Endpoints backend actually handles these requests at the path /_ah/spi.
          【解决方案10】:

          问题是你的python文件找不到导入:

          from protorpc import remote
          

          因此使用终端,跳过 GUI,导航到 appengine sdk 目录并将您的项目放在那里。对于 mac,它是:

          /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/
          

          【讨论】:

            【解决方案11】:

            我遇到了同样的问题,但事实证明我在 localhost 上指定了错误的端口。当开发服务器启动时,日志会在 localhost 上指定三个独立端口:

            INFO 2015-07-26 03:46:56,023 api_server.py:172] 启动 API 服务器:http://localhost:35714

            INFO 2015-07-26 03:46:56,027 dispatcher.py:186] 启动模块“默认”运行在:http://localhost:8080

            INFO 2015-07-26 03:46:56,028 admin_server.py:118] 在以下位置启动管理服务器:http://localhost:8000

            问题是我试图将端口用于 api 服务器,但您只需将端口用于默认模块。

            这有效:http://localhost:8080/_ah/api/explorer(我需要单击 chrome 中的盾牌并允许不安全的脚本,因为 url 未加密)

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2022-01-07
              • 2019-09-30
              • 1970-01-01
              • 2021-05-31
              • 2021-12-27
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多