0

I'm simply trying to add the Firebase Admin SDK to my Python script, but am unable to import the database module due to a TypeError in one of the library's python scripts.

I installed the library as instructed:

sudo pip install firebase-admin

I initialized the Firebase Admin SDK as instructed:

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

But it breaks:

>>> import firebase_admin
>>> from firebase_admin import credentials
>>> from firebase_admin import db
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda/lib/python3.6/site-packages/firebase_admin/db.py", line 33, in <module>
    from firebase_admin import _http_client
  File "/anaconda/lib/python3.6/site-packages/firebase_admin/_http_client.py", line 30, in <module>
    raise_on_status=False, backoff_factor=0.5)
TypeError: __init__() got an unexpected keyword argument 'status'

I peeked into the problematic script _http_client.py and saw that it imports requests, so I updated that with pip, to no avail.

No idea what could be the problem here. Any help would be much appreciated! Thank you!

KENdi
  • 7,576
  • 2
  • 16
  • 31
Jenna
  • 21
  • 1
  • 4
  • What's your version of urllib3? Looks like your version's `util.retry.Retry` class does not yet accept the `status` argument. Maybe try to update that package as well. – shmee Feb 12 '19 at 07:48
  • @shmee I was at 1.22 before, upgraded to 1.24.1 at your suggestion, but still got the same error message. – Jenna Feb 12 '19 at 16:12
  • Um ... seeing that your program runs in an anaconda env and that you used pip for the upgrade, I have to ask: are you sure that you did the upgrades on the correct interpreter version? – shmee Feb 12 '19 at 16:27
  • I'm... pretty sure? ```Requirement already up-to-date: urllib3 in /anaconda/lib/python3.6/site-packages (1.24.1)``` – Jenna Feb 12 '19 at 16:47
  • Yeah, OK :) Please don't mind the question. Still, unless I absolutely miss sth. here, the exception raises when `requests.packages.urllib3.util.retry.Retry` is instantiated in `_http_client`. I wonder if maybe sth. is messing up `sys.path` in that env. Could you please run a script that just does `import requests; print(requests.packages.urllib3.util.retry.__file__)` in that same interpreter and verify that it in fact imports the module from the urllib3 package in `/anaconda/lib/python3.6/site-packages`? – shmee Feb 12 '19 at 17:40
  • https://stackoverflow.com/questions/30456573/why-has-anaconda-added-my-default-python-paths-to-the-specific-environments-pat this _might_ be related – shmee Feb 12 '19 at 17:44
  • Ha no worries, I was just scared that the problem really was that obvious. But it does look like it's importing from the same package: ```/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/util/retry.py``` – Jenna Feb 12 '19 at 19:06
  • Printing sys.path returns ten paths to ```/anaconda/lib/python3.6/``` and one path to ```/Users/jxu2/.local/lib/python3.6/site-packages```. Could that be the problem? Sorry you have to hold my hand through this :/ – Jenna Feb 12 '19 at 19:12
  • No need to apologize. I actually find this quite an interesting problem ;) Yes, that one path to `/Users` might actually cause the issue. Do you have the environment variable `PYTHONPATH` set in the environment of that user jxu2? If so, try to unset it. If not, `conda info -a` might help identifying the origin of that entry. However, I'm a bit puzzled that the `retry` module appears to be located directly in the `requests` package. I would have expected it to be `/anaconda/lib/python3.6/site-packages/urllib3/util/retry.py`. – shmee Feb 12 '19 at 19:29
  • Otherwise, it would be interesting to see if the class `Retry` in `/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/util/retry.py` actually takes an argument `status` in its `__init__` method. – shmee Feb 12 '19 at 19:33
  • Nooope, PYTHONPATH isn't set in jxu2. As for the ```__init___``` method in ```retry.py```, it accepts the following arguments: ```self, total=10, connect=None, read=None, redirect=None, method_whitelist=DEFAULT_METHOD_WHITELIST, status_forcelist=None, backoff_factor=0, raise_on_redirect=True, raise_on_status=True, history=None, respect_retry_after_header=True``` – Jenna Feb 13 '19 at 01:00
  • That sure looks like an old `urllib3` version. The `status` option has been added in this PR nearly 2 years ago: https://github.com/urllib3/urllib3/pull/1148. It has first appeared in the 1.21.0 release as far as I can tell: https://github.com/urllib3/urllib3/blob/1.21/urllib3/util/retry.py#L152 – Hiranya Jayathilaka Feb 13 '19 at 01:12

3 Answers3

1

Turns out, there was an old version of urllib3 lurking in my requests package. Removing the former from the latter did the trick. Thanks to shmee and Hiranya Jayathilaka for leading me to the solution!

Jenna
  • 21
  • 1
  • 4
  • Huh? Now I wonder how an outdated urllib3 package ended up directly in `requests`. Normally, `packages` is a module that does some import wizardry to localize 3rd party packages ... oh well :) Cool that you found it! – shmee Feb 13 '19 at 06:39
  • @shmee I have no idea, my environment is probably a disaster (due to a decade of countless attempts to learn various programming languages). Hence my somehow using pip and anaconda simultaneously... anyway, thanks so much for all your help! – Jenna Feb 13 '19 at 16:15
1

Leaving an answer here to help people who are googling this find it easily.

Link to issue 262 on GitHub

You can check your version with:

import requests
from requests.packages import urllib3
print(urllib3.__version__)
>>>"1.16.1" # my output

You can check the location of the urllib3 you are using with:

import requests
from requests.packages import urllib3
print(urllib3.__file__)
>>>'...anaconda3/lib/python3.6/site-packages/requests/packages/urllib3/__init__.py'

If you are using Anaconda, you can physically remove the package, or you can just run conda update urllib3 in a terminal. That worked for me.

russellthehippo
  • 402
  • 4
  • 10
1

this worked for me , i just searched for the location of urllib3 package and then i deleted it . you can find the location of the package by taping the following commands in python interpreter

from requests.packages import urllib3
print (urllib3.__file__)