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!
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!
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.
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__)
Related
I am trying to launch a script I wrote that is supposed to read data from a firebase db but it throws the following error:
Traceback (most recent call last):
File "myScript.py", line 8, in <module>
from firebase import Firebase
File "/Users/georgeoprea/Library/Python/3.8/lib/python/site-packages/firebase/__init__.py", line 20, in <module>
from Crypto.PublicKey import RSA
ModuleNotFoundError: No module named 'Crypto'
I have tried to install Crypto in the following ways:
pip3 install Crypto
pip3 install pycryptodome
When I run pip3 show Crypto I get the following output:
Name: crypto
Version: 1.4.1
Summary: Simple symmetric GPG file encryption and decryption
Home-page: https://github.com/chrissimpkins/crypto
Author: Christopher Simpkins
Author-email: git.simpkins#gmail.com
License: MIT license
Location: /Users/georgeoprea/Library/Python/3.8/lib/python/site-packages
Requires: Naked, shellescape
Required-by:
This is the list of imports I have in myScript.py:
from bs4 import BeautifulSoup
import time
import smtplib
from datetime import datetime
import json
import random
from email.message import EmailMessage
from firebase import Firebase
OS info: macOS 12.1 running on M1 Pro.
What could I do to have my script recognise the Crypto module?
This might be somewhat related to this question.
/e:
Ok, since you are using this firebase package, I can hopefully help you out.
First of all, it's the package's fault that it isn't running. While it depends on many external packages, it has none of them defined.
This is what I had to do in a clean virtual environment just to be able to do from firebase import Firebase:
pip install sseclient python_jwt gcloud pycryptodome requests-toolbelt
Here is the requirements.txt I ended up with in the clean environment. Notice, that this was only for importing a single class from the package. There still might be other dependencies hidden somewhere, waiting to throw an exception.
I encourage you to give feedback to the developer about this issue. Even better, fix this yourself and open a Pull Request. You might help others with the same issue.
I found a workaround for this. I simply used another module to read from the firebase db. Instead of using firebase I used firebase_admin as mentioned in the firebase documentation. firebase_admin doesn't use Crypto so there's no more problem from this point of view. However I had to change a little bit how I retrieve and write data.
I have a couple of firebase python files, one that writes to my database fine, and one that retrieves data from my firebase database no problem. They are both written in Python 3.5.3. I have a flask website that I am developing, as soon as I use the
import firebase_admin
in MyFlaskApp.py it throws up the error no module named firebase_admin and I get the following error.
flask.cli.NoAppException: While importing "TrialPage", an ImportError was
raised:
Traceback (most recent call last):
File "/home/pi/Documents/WebFlask/venv/lib/python3.5/site-
packages/flask/cli.py", line 236, in locate_app
__import__(module_name)
File "/home/pi/Documents/WebFlask/TrialPage.py", line 1, in <module>
from firebase_admin import firebase_admin
ImportError: No module named 'firebase_admin'
my other files work completely fine, I can understand why this wont work with my flask file. I have even tried creating a brand new MyFlaskApp.py file just incase something was corrupt with the existing file I am using. This did not work.
This error is thrown up regardless of whether the import firebase_admin is at the very top of my file or underneath my other imports, or in the middle of a function.
The line from firebase_admin import firebase_admin suggests we're importing firebase_admin.py from firebase_admin package.
If we look into the firebase_admin package installed, we won't see a firebase_admin.py file.
I tried to replicate the error by intentionally using the same import line that you used and I can confirm that I get the same ImportError message.
I would suggest using the following import line instead:
import firebase_admin
Hope that helps!
I've seen this question asked before but none of the answers seem to work for me.
I am using python version 2.7.13
In my code I have ..
import base64
import httplib2
Now when I run it on my own pc it works fine, but when I run it on my works p.c. behind a firewall I get ..
Traceback (most recent call last):
File "mail4.py", line 2, in
import httplib2
File "C:\Python27\lib\site-packages\httplib2__init__.py", line 39, in
import urllib
File "C:\mypy\urllib.py", line 1, in
import requests
File "C:\Python27\lib\site-packages\requests__init__.py", line 43, in
import urllib3
File "C:\Python27\lib\site-packages\urllib3__init__.py", line 8, in
from .connectionpool import (
File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 35, in
from .request import RequestMethods>
File "C:\Python27\lib\site-packages\urllib3\request.py", line 10, in >
from .packages.six.moves.urllib.parse import urlencode
ImportError: cannot import name urlencode
I've tried setting proxies.
I've tried uninstalling and re-installing six
Also
from urllib.parse import urlencode
All to no avail ?
You are (in this case) apparently running Python 2.7.x, however parse module is in urllib package in Python 3.x. In Python 2.x its name was (just) urlparse. Based on that, I'd guess different configuration (mismatch in versions used between Code and/or 3rd party packages and/or python interpreter is behind the problem you're seeing).
EDIT: sorry, I should have also noticed you are looking for urlencode on the last bit. In python 2.7 that is a function in urllib module: from urllib import urlencode.
I fixed this issue with installing Werkzeug to <1.0, which removed the contrib module
pip install Werkzeug==0.16.1
I have installed Google APIs Client Library for Python via easy_install.py --upgrade google-api-python-client. When I run a script that contains from oauth2client.tools import argparser, run_flow returns:
Traceback (most recent call last):
File "C:\Users\name\Desktop\file.py", line 9, in <module>
from oauth2client.tools import argparser, run_flow
ImportError: cannot import name argparser
I am using python 2.7.6 64x in win 8. The strange thing is that doing the same procedure in another pc in win 7 it working perfect. What is going wrong?
Thanks.
The argparser object was added on 29 March 2013, after google-api-python-client version 1.1 was released.
It appears your easy_install.py --upgrade google-api-python-client call failed to upgrade your local installation, you are still trying to import from version 1.1. The output of import oauth2client.tools; print oauth2client.tools.__file__ shows this:
C:\Python27\lib\site-packages\google_api_python_client-1.1-py2.7.egg\oauth2client\tools.pyc
You can see the version number in the egg path.
I'm following this tutorial:
http://boto.cloudhackers.com/en/latest/cloudsearch_tut.html
I've installed boto 2.6. The command:
conn = boto.connect_cloudsearch()
produces the error:
>>> conn = boto.connect_cloudsearch()Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "boto/__init__.py", line 616, in connect_cloudsearch
from boto.cloudsearch.layer2 import Layer2
File "boto/cloudsearch/layer2.py", line 26, in <module>
from .domain import Domain
File "boto/cloudsearch/domain.py", line 34, in <module>
from .document import DocumentServiceConnection
File "boto/cloudsearch/document.py", line 30, in <module>
import requests
ImportError: No module named requests
How do I find the missing requests module?
requests is a third-party module that is a pre-resquite for that module, either do:
pip install requests
or
easy_install requests
If these don't work for you, it is on github.
Having this module will then give you access to boto.
At time of writing,
boto (2.8.0) requires a pretty old requests module, specifically
pip install requests==0.14.2
if you use >1.0.0 when using document.doc_service.commit() you get
TypeError: request() got an unexpected keyword argument 'config'
Got it. On the command line type:
easy_install requests
The requests module is a third party library for simplifying HTTP from Python. Info and installation instructions can be found on PyPi http://pypi.python.org/pypi/requests
You should use pip to install boto which will download necessary requirements, including requests. The other requirements are captured in the requirements.txt file in the boto source.
pip install boto
I can verify that a requests upgrade from 0.14.1 to version 0.14.2 cleared up the issues I was having with a similar error. I was initially confused because most people upgrade boto to 2.4 or higher and fixed the problem.
Just a note - I specifically installed 0.14.2 - not 1.0 or higher, which has its own problems in our setup.