Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GAE Standard - TransportError: ('Connection broken: IncompleteRead(38 bytes read) #166

Closed
linhtx opened this issue May 17, 2018 · 3 comments

Comments

@linhtx
Copy link

linhtx commented May 17, 2018

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Google App Engine Standard
  • Firebase SDK version: 2.10.0
  • Library version: _____
  • Firebase Product: database

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I installed GAE standard (python), firebase-admin.
When use function of firebase-admin, it doesn't work.

Console output:
logMessage: "TransportError: ('Connection broken: IncompleteRead(38 bytes read)', IncompleteRead(38 bytes read))"

Relevant Code:

app.yaml

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: main.app

libraries:
- name: flask
  version: 0.12
- name: ssl
  version: latest
  
env_variables:
  GAE_USE_SOCKETS_HTTPLIB: 'true'

appengine_config.py

from google.appengine.ext import vendor

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

Code

import firebase_admin
from firebase_admin import credentials, auth

cred = credentials.Certificate("key/asgsagahaha.json") 
default_app = firebase_admin.initialize_app(cred)

class Test():
    def __init__(self):
        pass

    def create_user(self):
        usr = auth.create_user() // Error at here
        print usr.uid
@hiranya911
Copy link
Contributor

As mentioned in my response on the Google group, you need to follow the instructions at https://google-auth.readthedocs.io/en/latest/user-guide.html#the-app-engine-standard-environment

(specifically the bit regarding the requests-toolbelt library)

@sww314
Copy link

sww314 commented Nov 25, 2019

This helped me:
https://groups.google.com/forum/#!topic/firebase-talk/FzEG2U6SRN8

I solved with requests-toolbelt module, which is described in
https://stackoverflow.com/questions/9604799/can-python-requests-library-be-used-on-google-app-engine

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'

@hamx0r
Copy link

hamx0r commented Apr 7, 2020

A critical piece of this is that, when using firebase, you must import firebase modules after monkeypatching, like this:

import requests
import requests_toolbelt.adapters.appengine
requests_toolbelt.adapters.appengine.monkeypatch()

# Now that we've imported requests, the toolbelt, and finished monkeypatch(), we can import firebase:
from firebase_admin import auth, initialize_app  # This must go after the monkeypatch()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants