AssertionError:找不到服务的api代理" urlfetch"

时间:2015-08-03 00:47:45

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

我正在使用stripe API与Stripe服务进行通信。 Google AppEngine甚至无法导入或参与此处,但我看到与GAE库相关的这个奇怪的AssertionError。下面是堆栈跟踪。什么可能出错?

$ 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"

2 个答案:

答案 0 :(得分:8)

这看起来像你运行unittests并尝试从测试中调用urlfetch。

我在胜利时做同样的事情,然后我得到以下转储:

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;

除了dirnames之外,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

答案 1 :(得分:0)

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())