firebase-admin-python sdk on app engine

682 views
Skip to first unread message

Ozgun Gunay

unread,
Sep 14, 2017, 2:08:53 PM9/14/17
to Firebase Google Group

I need to use firebase-admin-python sdk on app engine  (python 2.7). 

I installed the library under lib folder in my project;
pip install -t lib/ firebase-admin

I noticed that it has *.pyc files, which doesn't support from google.

Also, when I try to import the library with below command, I get error;
from lib.firebase_admin import credentials

Can this library works on the appengine? if yes, How? if no, What do you recommend?

Thanks




Kato Richardson

unread,
Sep 14, 2017, 2:19:34 PM9/14/17
to Firebase Google Group
Hi Ozgun, great questions. Could you file this against the Python Admin SDK repo? I'll ping our guru to check it out.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/96239341-2137-4317-9a21-250d48e87310%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Kato Richardson

unread,
Sep 14, 2017, 2:20:39 PM9/14/17
to Firebase Google Group

Samuel Stern

unread,
Sep 14, 2017, 4:31:04 PM9/14/17
to fireba...@googlegroups.com
Hi Ozgun,

A teammate of mine ran into the exact same thing the other day, and he got around it.  Here;s what he said:

"""
you can delete the .pyc files as they are just the precompiled versions of the .py files that are also there (and will be regenerated when .py is executed).

importing from lib worked for me after I added the appengine_config.py to my project root with the following content:

from google.appengine.ext import vendor

# Add any libraries installed in the "lib" folder.
vendor.add('lib')


I also had to explicitly NOT load the package from the app.yaml
"""

Hope that helps!

- Sam

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

Kato Richardson

unread,
Sep 15, 2017, 12:50:52 PM9/15/17
to Firebase Google Group
Also depending on how you use the SDK in App Engine, you might also have to do the additional steps documented at https://google-auth.readthedocs.io/en/latest/user-guide.html#the-app-engine-standard-environment.

On Thu, Sep 14, 2017 at 1:30 PM, 'Samuel Stern' via Firebase Google Group <fireba...@googlegroups.com> wrote:
Hi Ozgun,

A teammate of mine ran into the exact same thing the other day, and he got around it.  Here;s what he said:

"""
you can delete the .pyc files as they are just the precompiled versions of the .py files that are also there (and will be regenerated when .py is executed).

importing from lib worked for me after I added the appengine_config.py to my project root with the following content:

from google.appengine.ext import vendor

# Add any libraries installed in the "lib" folder.
vendor.add('lib')


I also had to explicitly NOT load the package from the app.yaml
"""

Hope that helps!

- Sam
On Thu, Sep 14, 2017 at 11:08 AM Ozgun Gunay <ozgun...@gmail.com> wrote:

I need to use firebase-admin-python sdk on app engine  (python 2.7). 

I installed the library under lib folder in my project;
pip install -t lib/ firebase-admin

I noticed that it has *.pyc files, which doesn't support from google.

Also, when I try to import the library with below command, I get error;
from lib.firebase_admin import credentials

Can this library works on the appengine? if yes, How? if no, What do you recommend?

Thanks




--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/96239341-2137-4317-9a21-250d48e87310%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ozgun Gunay

unread,
Sep 16, 2017, 4:57:31 PM9/16/17
to Firebase Google Group


Hi Samuel,

I did what you recommend. Probably it started to work. Thanks.
But I get IncompleteRead error, while trying to create a new user with below code .
How did your teammate solve this problem?


23:05:42.497/base/data/home/apps/s~uth-og/1.404154350035608234/lib/urllib3/util/ssl_.py:339: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
23:05:42.497 SNIMissingWarning
23:05:42.498/base/data/home/apps/s~uth-og/1.404154350035608234/lib/urllib3/util/ssl_.py:137: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
23:05:42.498 InsecurePlatformWarning

23:05:42.637https://accounts.google.com:443 "POST /o/oauth2/token HTTP/1.1" 200 None (/base/data/home/apps/s~uth-og/1.404154350035608234/lib/urllib3/connectionpool.py:396)
23:05:42.638('Connection broken: IncompleteRead(213 bytes read)', IncompleteRead(213 bytes read)) (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py:1552) Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__ rv = self.handle_exception(request, response, e) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__ rv = self.router.dispatch(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher return route.handler_adapter(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__ return handler.dispatch() File "/base/data/home/apps/s~uth-og/1.404154350035608234/framework/request_handler.py", line 38, in dispatch RequestHandler.dispatch(self) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch return self.handle_exception(e, self.app.debug) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~uth-og/1.404154350035608234/app/register.py", line 78, in post disabled=False) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/firebase_admin/auth.py", line 194, in create_user uid = user_manager.create_user(**kwargs) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/firebase_admin/_user_mgt.py", line 215, in create_user response = self._request('post', 'signupNewUser', json=payload) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/firebase_admin/_user_mgt.py", line 306, in _request resp = self._session.request(method, ID_TOOLKIT_URL + urlpath, **kwargs) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/google/auth/transport/requests.py", line 176, in request self._auth_request, method, url, request_headers) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/google/auth/credentials.py", line 121, in before_request self.refresh(request) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/google/oauth2/service_account.py", line 322, in refresh request, self._token_uri, assertion) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/google/oauth2/_client.py", line 143, in jwt_grant response_data = _token_endpoint_request(request, token_uri, body) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/google/oauth2/_client.py", line 104, in _token_endpoint_request method='POST', url=token_uri, headers=headers, body=body) File "/base/data/home/apps/s~uth-og/1.404154350035608234/lib/google/auth/transport/requests.py", line 115, in __call__ raise exceptions.TransportError(exc) TransportError: ('Connection broken: IncompleteRead(213 bytes read)', IncompleteRead(213 bytes read))


Test Code:

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from firebase_admin import auth


cred = credentials.Certificate('serviceAccountKey.json')
default_app = firebase_admin.initialize_app(cred)

user = auth.create_user(
email_verified=False,
phone_number='+15555550100',
password='secretPassword',
display_name='John Doe',
disabled=False)
print 'Sucessfully created new user: {0}'.format(user.uid)





14 Eylül 2017 Perşembe 23:31:04 UTC+3 tarihinde Samuel Stern yazdı:

Ozgun Gunay

unread,
Sep 18, 2017, 2:45:24 PM9/18/17
to Firebase Google Group


pip install -t lib/ requests-toolbelt and below code in appengine_config.py:

import requests
import requests_toolbelt.adapters.appengine

# Use the App Engine Requests adapter. This makes sure that Requests uses
# URLFetch.
requests_toolbelt.adapters.appengine.monkeypatch()

# also monkey patch platform.platform() from https://code.google.com/p/googleappengine/issues/detail?id=12982
import platform

def patch(module):
    def decorate(func):
        setattr(module, func.func_name, func)
        return func
    return decorate


@patch(platform)
def platform():
    return 'AppEngine'


Samuel Stern

unread,
Sep 18, 2017, 3:19:16 PM9/18/17
to Firebase Google Group
Hey Ozgun,

Glad you solved this, and thanks for sharing your solution with the community!

- Sam

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages