gpt4 book ai didi

python - 断言错误 : No api proxy found for service "urlfetch"

转载 作者:太空宇宙 更新时间:2023-11-03 12:46:45 24 4
gpt4 key购买 nike

我正在使用 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"

最佳答案

这看起来像您运行单元测试并尝试从测试中调用 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 中包括测试平台激活、停用和 urlfetch stub 调用,例如:

@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 服务。

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

关于python - 断言错误 : No api proxy found for service "urlfetch",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31778045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com