I am using stripe
API to talk to Stripe services. Google AppEngine doesn't even get imported or involved here, but I am seeing this weird AssertionError
related to GAE libraries. Below is the stacktrace. What could possibly go wrong?
$ 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"
This looks like you run unittests and try to call urlfetch from the tests.
I do the same on win, then I get the following dump:
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 268, in fetch
rpc = create_rpc(deadline=deadline)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 224, in create_rpc
return apiproxy_stub_map.UserRPC('urlfetch', deadline, callback)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 414, in __init__
self.__rpc = CreateRPC(service, stubmap)
File "C:\Program Files (x86)\Google\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"
Should make no difference between Unix/Win except for the dirnames, but as in both cases this comes from the apiproxy_stub_map.py, I assume that you ran it from unittests.
What solves the issue for me with my unittests is to do the following, maybe this works for your issue as well:
In the TestCase include the testbed activation, deactivation and urlfetch stub calls, e.g.:
@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()
The call cls.testbed.init_urlfetch_stub()
does the trick for me to activate the urlfetch service.
In the docs is a list of all the stubs for the different services that you have to call to work with unittests: https://cloud.google.com/appengine/docs/python/tools/localunittesting
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With