Trouble importing HTTPTokenAuth from flask_httpauth - python-3.x

I am trying to use token authentication for a Flask project.
from flask_httpauth import HTTPBasicAuth # works
from flask_httpauth import HTTPTokenAuth # does not work.
I get the following error
ImportError: cannot import name HTTPTokenAuth
I tried
pip install flask_httpauth --upgrade
But it claims everything is up to date. (Flask-HTTPAuth==3.1.1)
The docs suggest this is the proper way to import it, but for some reason it is not working. Any ideas how I can get the token auth to import?
Edit:: I deleted and recreated the virtual environment I was using.
I am using python anywhere.
The problem persists. I discovered an older version of Flask_httpauth is loaded by default (v2.2.0 instead of v3.1.1). I went into the site packages and saw the HTTPTokenAuth is there and should be called.
I tried doing
import flask_httpauth
print (flask_httpauth.__version__)
to check the version being called by my app, but that doesnt work for all python packages, and it seems flask_httpauth doesnt have that functionality.
There are no errors displayed where I have the virtual enviorment linked on the web tab of pythonanywhere.

PythonAnywhere dev here, just reposting the solution that was discovered from #ExperimentsWithCode's forum post. The problem was happening when the code was being run from the editor on PythonAnywhere. This is separate from the configuration that is done on the "Web" tab where the virtualenv was specified: people can run any code they want from the editor, regardless of which web app it's associated with, or even code that's not associated with a web app.
So the solution was what #Miguel suggested: use a shebang.

Related

Cloud Firestore for android apps built in Kivymd not working with buildozer

Me and a friend are creating android app in Kivymd. We did create a database using firebase.
But we used the firestore option than the realtime database. We really like the feature and want to keep it. Everything works fine when we compile the app on our Ubuntu environment. But when we add firebase-admin in our requirements in the buildozer.spec file we get alot of errors related to google-cloud, google-protobuf and the list goes on. We have been looking everywhere on the internet but we cant find a solution. And all of these packages are installed with pip and we have verified this.
When using our original requirements string such as:
requirements = python3,kivy==2.0.0rc3,kivymd,sdl2_ttf==2.0.15,android,plyer,requests,urllib3,chardet,idna,hostpython3
Everything works fine, but when we add firebase_admin to the requirements we get No module errors that makes the requirements string getting very long. And we have installed everything u can possibly think related to the google packages with pip.
We have been exploring on maybe creating our own recipe, but we would be very happy if anyone could just lead us in the right direction. Our current requirements string is so long that i wont post it here. We have made realtime database work because it only uses requests so maybe we need to skip using firestore. Below are the packages we use to use and are the root cause of why the app does not work in the android app with buildozer.
import firebase_admin
from firebase_admin import credentials, firestore, exceptions
I have a feeling we must create a recipe or that its not even possible to use with kivymd and android. But any help would be very appreciated.

lxml library in AWS Lambda

I've included this library as a layer to my lambda function but when I go to test it I get the error: cannot import name 'etree' from 'lxml'
There are multiple posts about people having this issue and some say to that I need to build it to compile some c libraries. Most posts say to look for another file or folder name 'lxml' which I've verified is not the issue.
I'm able to run the same code I've deployed to my layer on my local linux workstation and it runs without an issue.
Turns out my lambda was running python version 3.8 and that version is not compatible with the version of lxml I am using 4.5.1. Changing the run time to 3.7 fixed the issue. Hope this helps someone.

ImportError: No module named 'kivy'

I have 3 Projects:
The weather app from the Book "Creating Apps in Kivy" that i have completed.
A StudentDB app from a Youtube Tutorial.
The beginning of my own app.
The first two still work. But if i want to build my own, kivy is not known.
I have thrown everything out but the basics. I do not know why kivy only runs for project my first projects. I had no issue with the other ones. But i cannot escape the issue.
I have tried pip install kivy but it is already installed, i do not know the version though.
I use Python 3.5.6 in the Anaconda bundle.
I have tried making a new Project and abandoning my old.
Begin of code i used
from kivy.app import App
class BasicApp(App):
pass
End of code i used
Does anyone know this issue? Do i have to install something special? I am not sure how to handle this one.

Python NLTK using local nltk_data

I've been recently working with NLTK library for language processing. I can normally install packages using nltk.download('package'), if I have the internet access etc.
The problem arises, If I try to run my code offline on a cluster. Here,
from nltk.tag import PerceptronTagger
ImportError: cannot import name 'PerceptronTagger'
and similar errors emerge, as nltk can't seem to find the nltk_data folder. I tried:
nltk.data.path.append("./nltk_data"), where I copied nltk_data along with code.
nltk.download('punct') #,download_dir="./nltk_data"), but this doesn't work, as there is no internet access.
Question is then, how can I use nltk_data locally?
Thanks.
It appears the machine I was running this on had NLTK 3.0.2, hence updating NLTK solved the problem all together.

Where is the BlockBlobService Class Located in Python Azure Module?

I am pretty new to using the microsoft azure service and trying to follow the tutorial in https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python Using Python 3.5.6 in conda 4.5.11 distribution on a Windows PC.
The first problem I am facing while importing azure is I cannot see the version the usual way. That means
azure.__version__
gives an error.
Then, this line of the code gives me an error saying it can neither import names BlockBlobService, nor PublicAccess. Seems like both have been deprecated or I am myself using some old version.
from azure.storage.blob import BlockBlobService, PublicAccess #Option 1
However, the following import is working.
from azure.storage.blob import BlobService #Option 2
But the problem with this is after I create a local file and try to upload with a create_blob_from_path method (as advised in the tutorial), the method is either non-existent or deprecated.
I looked around the web for solution of this BlockBlobService issue, and seemed there has been a persistent confusion around the correct module hierarchy and class names to import. One user, for example, got some official documentation from the library which advised this, which also does not work.
from azure.storage import BlobService #Option 3
Still someone else reported some complaint with this, which is working on my system at least. But this does not import the needed Blob object.
import azure.storage.blob #Option 4
Further, according to this documentation, https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.blockblobservice.blockblobservice?view=azure-python
the BlockBlobService class is located in azure.storage.blob.blockblobservice module. But the interpreter throws an import error when I try to import that as well.
Most of the proposed solutions are around some upgrading/downgrading of versions, but, silly me, somehow I cannot even find the version of the azure module like I do for other modules. Also, it seems many of the solutions are for pip3 running on Linux, whence I am using conda 4.5.11 on Windows. So how to make the azure API work?
As of November 2020, Azure maintains two versions of storage SDK:
v12 (Link)
v2.1 (Link)
2.1 is considered to be the legacy version of the API (Link):
This quickstart uses a legacy version of the Azure Blob storage client library. To get >started with the latest version, see Quickstart: Manage blobs with Python v12 SDK.
BlockBlobService is located in v2.1 and should be avoided. Use v12 version instead.
On windows, you should use pip install azure.
My environment is windows 10 with python 3.6.5, but I didn't use conda.
First, in cmd, run pip install azure, screenshot as below:
Then in pycharm, try use the from xxx import xx, screenshots as below:
For BlockBlobService:
For PublicAccess:
The BlockBlobService location:

Resources