Pyrebase4 error cannot import name 'gaecontrib'
Asked Answered
T

2

7

I have been trying to install pyrebase4 using pip install pyrebase4 but when ran it throws below error

"C:\Users\ChodDungaTujheMadhadchod\anaconda3\envs\sam_upgraded\lib\site-packages\requests_toolbelt\adapters\appengine.py", line 42, in <module> from .._compat import gaecontrib ImportError: cannot import name 'gaecontrib' from 'requests_toolbelt._compat'

As I see the error direct directly to requests_toolbelt , but I cannot figure out the possible way to fix it, I tried upgrading to latest version as which is requests-toolbelt==1.0.0 . So is there any way to fix it.

Tuantuareg answered 9/5, 2023 at 10:34 Comment(0)
T
12

Okay so what I found that the latest requests-toolbelt 1.0.1 is currently throwing this issue. So downgrading it to next previous version requests-toolbelt==0.10.1 fixes the issue.

Tuantuareg answered 9/5, 2023 at 10:49 Comment(1)
No this does not work. Instead it crashes on: ImportError: cannot import name 'appengine' from 'urllib3.contrib'. Also the latest requests-toolbelt version as of 2024-06-25 is 1.0.0.Twofold
P
3

My reply is a little late, but I discovered a another way to solve this error. This error, such you sayd, is something associated with the version. You can read this github issue that sayd:

We claim urllib3 works with AppEngine but looks like it's broken today (as of a few months ago). Nobody on our core team uses AppEngine, so maintaining support for it has been a substantial drain.

It means that the urllib3, requests and requests-toolbelt actualy don't have suport from AppEngine, and the pyrebase import this dependencies to have compatibility. If you want to solve without loss the new atualizations, you can remove from the pyrebase file these lines:

19 - from requests.packages.urllib3.contrib.appengine import is_appengine_sandbox
20 - from requests_toolbelt.adapters import appengine

And replace this line:

# 82 - adapter = appengine.AppEngineAdapter(max_retries=3)
82 - raise Exception('Appengine is not supported by pyrebase.')

You will need to have a way to discover if is a appengine, what is_appengine_sandbox did. So in the firsts lines you paste this function:

def is_appengine_sandbox():
    appengine_runtime = 'APPENGINE_RUNTIME' in os.environ
    is_local_appengine = (appengine_runtime and 'Development/' in os.environ['SERVER_SOFTWARE'])
    is_prod_appengine = (appengine_runtime and 'Google App Engine/' in os.environ['SERVER_SOFTWARE']
                         and not is_prod_appengine_mvms)
    is_prod_appengine_mvms = os.environ.get('GAE_VM', False) == 'true'
    return (is_local_appengine or is_prod_appengine or is_prod_appengine_mvms) and not is_prod_appengine_mvms

It's the static def from is_appengine_sandbox

It's a temporary solution, maybe somebody with more experience in AppEngine will create a updated version from this, that accept AppEngine support.

OBS: If you can downgrade, will be better. It's answer is only if you need the newest libraries.

Palmate answered 14/6, 2023 at 20:24 Comment(1)
That's a nice workaround. I've got a problem with kubeflow pipelines. lib/python3.11/site-packages/kfp/_auth.py - move import requests_toolbelt.adapters.appengine just before the place it's used. I will not get called (and crash) unless running on AppEngine.Twofold

© 2022 - 2024 — McMap. All rights reserved.