【问题标题】:AssertionError: No api proxy found for service "urlfetch"AssertionError:未找到服务“urlfetch”的 api 代理
【发布时间】:2015-10-25 00:20:37
【问题描述】:

我正在使用stripe API 与 Stripe 服务通信。 Google AppEngine 甚至没有在这里导入或参与,但我看到这个奇怪的AssertionError 与 GAE 库相关。下面是堆栈跟踪。可能会出什么问题?

$ python stripe_export.py 
Traceback (most recent call last):
  File "stripe_export.py", line 99, in <module>
    etl_customers()
  File "stripe_export.py", line 72, in etl_customers
    customers = fetch_data(stripe.Customer)
  File "stripe_export.py", line 54, in fetch_data
    _list_obj = cls.all(limit=page_size)
  File "/Library/Python/2.7/site-packages/stripe/resource.py", line 332, in all
    response, api_key = requestor.request('get', url, params)
  File "/Library/Python/2.7/site-packages/stripe/api_requestor.py", line 140, in request
    method.lower(), url, params, headers)
  File "/Library/Python/2.7/site-packages/stripe/api_requestor.py", line 249, in request_raw
    method, abs_url, headers, post_data)
  File "/Library/Python/2.7/site-packages/stripe/http_client.py", line 160, in request
    payload=post_data
  File "/usr/local/google_appengine/google/appengine/api/urlfetch.py", line 268, in fetch
    rpc = create_rpc(deadline=deadline)
  File "/usr/local/google_appengine/google/appengine/api/urlfetch.py", line 224, in create_rpc
    return apiproxy_stub_map.UserRPC('urlfetch', deadline, callback)
  File "/usr/local/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 414, in __init__
    self.__rpc = CreateRPC(service, stubmap)
  File "/usr/local/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 68, in CreateRPC
    assert stub, 'No api proxy found for service "%s"' % service
AssertionError: No api proxy found for service "urlfetch"

【问题讨论】:

    标签: python google-app-engine stripe-payments


    【解决方案1】:

    这看起来像您运行单元测试并尝试从测试中调用 urlfetch。

    我在 win 上做同样的事情,然后我得到以下转储:

    File &quot;C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py&quot;, line 268, in fetch
    rpc = create_rpc(deadline=deadline)
    File &quot;C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py&quot;, line 224, in create_rpc
    return apiproxy_stub_map.UserRPC('urlfetch', deadline, callback)
    File &quot;C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py&quot;, line 414, in __init__
    self.__rpc = CreateRPC(service, stubmap)
    File &quot;C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py&quot;, line 68, in CreateRPC
    assert stub, 'No api proxy found for service &quot;%s&quot;' % service
    AssertionError: No api proxy found for service &quot;urlfetch&quot;
    

    在 Unix/Win 之间应该没有区别,除了目录名,但在这两种情况下,这都来自 apiproxy_stub_map.py,我假设你是从单元测试中运行它的。

    通过我的单元测试为我解决问题的是执行以下操作,也许这也适用于您的问题:

    在 TestCase 中包括 testbed 激活、停用和 urlfetch 存根调用,例如:

    @classmethod
    def setUpClass(cls):
        cls.testbed = testbed.Testbed()
        cls.testbed.activate()
        cls.testbed.init_datastore_v3_stub()
        cls.testbed.init_memcache_stub()
        cls.testbed.init_urlfetch_stub()
    
    @classmethod
    def tearDownClass(cls):
        cls.testbed.deactivate()
    

    调用cls.testbed.init_urlfetch_stub() 可以让我激活 urlfetch 服务。

    文档中列出了您必须调用才能使用单元测试的不同服务的所有存根:https://cloud.google.com/appengine/docs/python/tools/localunittesting

    【讨论】:

      【解决方案2】:

      Per this Google Groups thread:

      from google.appengine.api import urlfetch_stub
      from google.appengine.api import apiproxy_stub_map 
      apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() 
      apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', 
      urlfetch_stub.URLFetchServiceStub()) 
      

      【讨论】:

        猜你喜欢
        • 2021-11-29
        • 2012-01-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多