断言错误:找不到服务“urlfetch”的 api 代理

问题描述 投票:0回答:3

我正在使用

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"
python google-app-engine stripe-payments
3个回答
11
投票

这看起来像您运行单元测试并尝试从测试中调用 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;

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

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

在测试用例中包括测试床激活、停用和 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


3
投票

根据此 Google 网上论坛主题

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

0
投票

所有建议的解决方案都不适合我。 (不涉及单元测试,并且设置 apiproxy 会导致证书问题。)

我必须删除

appengine-python-standard
包,并且很幸运,项目中不再需要需要它的依赖项。

pip uninstall appengine-python-standard

© www.soinside.com 2019 - 2024. All rights reserved.