A little background: I've been trying to make a restful server that can query and insert via the management API. After banging my head against the wall using node.js and javascript I switched over to python knowing it has more support.
Currently I am trying to follow the GA Tutorial: Hello Analytics API with a slight twist. I trigger the what was the main method in hello_analytics_api_v3.py when trying to access a particular end point on the server. This is only for testing. The method is called insertExperiment and attempts to insert an experiment into a private Google Analytics account.
However I'm always receiving the exception:
NotImplementedError('The gflags library must be installed to use tools.run(). Please install gflags or preferrably switch to using tools.run_flow().',)
Here is the full trace stack:
File "/0zzz/bottle.py", line 764, in _handle
return route.call(**args)
File "/0zzz/bottle.py", line 1575, in wrapper
rv = callback(*a, **ka)
File "server.py", line 39, in server_static
hello_analytics_api_v3.insertExperiment("xxxxxxx", "xxxxxxxxx", "xxxxxx", experiment_body)
File "/0zzz/hello_analytics_api_v3.py", line 11, in insertExperiment
service = hello_analytics_api_v3_auth.initialize_service()
File "/0zzz/hello_analytics_api_v3_auth.py", line 32, in
initialize_service
credentials = prepare_credentials()
File "/0zzz/hello_analytics_api_v3_auth.py", line 25, in
prepare_credentials
credentials = run(FLOW, storage)
File "/0zzz/oauth2client/tools.py", line 241, in run
'The gflags library must be installed to use tools.run(). '
NotImplementedError: The gflags library must be installed to use
tools.run(). Please install gflags or preferrably switch to using
tools.run_flow().
A few extra notes:
I have tried this exact same thing (invoking main on pinging the correct address) when copying the exact code from the Tutorial.
I have write access with the management API -- so that's not a problem here at all.
I thought there might be a namespace issue with one of my libraries (which also imports a run) but resolved this by renaming the other library.
GA Client Library is installed! as per the instructions on Hello Analytics API.
Thank you for any help you can provide!
I received the same error while running through a tutorial for google APIs called 'Google APIs Console Help'. The fix was simple in my case, just update the gflags library:
easy_install --upgrade python-gflags
You need to install gflags library.
$ wget https://python-gflags.googlecode.com/files/python-gflags-2.0.tar.gz
$ tar xfvz python-gflags-2.0.tar.gz ; cd python-gflags-2.0
$ python setup.py install
Related
https://raw.githubusercontent.com/paramiko/paramiko/master/demos/demo_server.py
I see the above demo_server of paramiko. But I don't see the instructions on how to run it. I run the following ./demo_server.py command. But once I run ssh robey#127.0.0.1 -p 2200, the server fails. Could anybody let me know the complete steps on how to run this example? Thanks.
$ python3 ./demo_server.py
Read key: 60733844cb5186657fdedaa22b5a57d5
Listening for connection ...
Got a connection!
*** Caught exception: <class 'ImportError'>: Unable to import a GSS-API / SSPI module!
Traceback (most recent call last):
File "./demo_server.py", line 140, in <module>
t = paramiko.Transport(client, gss_kex=DoGSSAPIKeyExchange)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/transport.py", line 445, in __init__
self.kexgss_ctxt = GSSAuth("gssapi-keyex", gss_deleg_creds)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/ssh_gss.py", line 107, in GSSAuth
raise ImportError("Unable to import a GSS-API / SSPI module!")
ImportError: Unable to import a GSS-API / SSPI module!
$ ssh robey#127.0.0.1 -p 2200
kex_exchange_identification: read: Connection reset by peer
I managed to get it to work, make sure to go through these steps (Thank you Sandeep for the pip insight), chances are you may be missing the Kerberos dependencies:
You may need to perform pip install gssapi in the CLI if that has not already been done (I'm using the Windows Command Prompt, Linux/WSL might need pip3 instead depending on your version of python)
From there you will need to import the gssapi library into the code at the top with the other imported libraries, so just call
import gssapi in demo_server.py
After running demo_server.py again, the CLI should eventually say something like it is missing files located in Program Files\ MIT\ Kerberos\ bin, as Kerberos is a dependency for gssapi, you can install it from here:
https://web.mit.edu/KERBEROS/dist/
Make sure you do custom install if you're not sure where it will be downloaded, so that you can set up the file location where the CLI says is missing in step 3 (Should automatically say Program Files\ MIT). I unchecked the boxes for auto-start and tickets, but not sure as to what your preferences may be. After all that, a computer restart is required.
I'm trying to run some Gstreamer examples for the Google Coral USB accelerator - I'm not using the Coral dev board. The driver is installed and works and I can classify images from my camera using OpenCV and the edgetpu library. I'd like to get the web server demo running. I've narrowed it down to Gstreamer not being able to find a plugin that Coral provides.
The plugins are from this repo (which also contains the demo code edgetpu_detect_server and edgetpu_detect: https://coral.googlesource.com/edgetpuvision/+/refs/heads/master/plugins/
There are three plugins that Coral provides:
linaro#linaro-alip:~$ ls /home/linaro/edgetpuvision/plugins/
glbox.py glsvgoverlaysink.py glsvgoverlaysrc.py
The error I get when trying to run, e.g. the detection server is:
(edgetpu_detect:28764): dbind-WARNING **: 11:38:56.589: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files
v4l2src device=/dev/video0 ! video/x-raw,format=YUYV,width=640,height=512,framerate=30/1 ! glupload ! tee name=t
t. ! queue ! glsvgoverlaysink name=glsink
t. ! queue max-size-buffers=1 leaky=downstream ! glfilterbin filter=glbox ! video/x-raw,format=RGB,width=300,height=300 ! appsink name=appsink emit-signals=True max-buffers=1 drop=True sync=False
Traceback (most recent call last):
File "/usr/local/bin/edgetpu_detect", line 11, in <module>
load_entry_point('edgetpuvision==1.0', 'console_scripts', 'edgetpu_detect')()
File "/home/linaro/.local/lib/python3.7/site-packages/edgetpuvision/detect.py", line 207, in main
run_app(add_render_gen_args, render_gen)
File "/home/linaro/.local/lib/python3.7/site-packages/edgetpuvision/apps.py", line 70, in run_app
display=args.displaymode):
File "/home/linaro/.local/lib/python3.7/site-packages/edgetpuvision/gstreamer.py", line 248, in run_gen
display=display)
File "/home/linaro/.local/lib/python3.7/site-packages/edgetpuvision/gstreamer.py", line 254, in run
run_pipeline(pipeline, layout, loop, render_overlay, display)
File "/home/linaro/.local/lib/python3.7/site-packages/edgetpuvision/gstreamer.py", line 300, in run_pipeline
pipeline = Gst.parse_launch(pipeline)
gi.repository.GLib.Error: gst_parse_error: no element "glsvgoverlaysink" (1)
I've installed gst-python from source as described here: lifestyletransfer.com/how-to-install-gstreamer-from-sources-on-ubuntu/
Seems to be OK, I've linked it against Python 3.7.
linaro#linaro-alip:$ gst-inspect-1.0 /usr/local/lib/gstreamer-1.0/libgstpython.cpython-37m-aarch64-linux-gnu.so
Plugin Details:
Name python
Description loader for plugins written in python
Filename /usr/local/lib/gstreamer-1.0/libgstpython.cpython-37m-aarch64-linux-gnu.so
Version 1.14.2
License LGPL
Source module gst-python
Binary package GStreamer GObject Introspection overrides for Python
Origin URL http://gstreamer.freedesktop.org
0 features:
However when I try to load the plugins, gst-inspect can't find them, e.g.
gst-inspect-1.0 --gst-plugin-path=$PWD | grep glbox
Is there some other configuration thing I need to do?
EDIT: Interestingly on the dev board itself (which works), the gstreamer libs don't even seem to be installed (there is no gst-inspect), but the demo clearly uses gstreamer somewhere via Python.
I would check if the python plugins are located in $GST_PLUGIN_PATH/python directory.
That plugin was made specifically for the dev board and is actually optimized for dev board's HW. I'm not so sure if there is a better easy way to get it working besides actually digging more into it.
Would this demo works?
https://github.com/google-coral/examples-camera/tree/master/gstreamer
There is a bug in gst-python (I've sent a patch upstream) whereby it fails to look in the right default places for python plugins. However it does correctly look in a 'python' subdirectory of wherever the various GST_PLUGIN_PATH environment variables point.
I have a simple python file that I am trying to set up to utilize sessions, when i run the file I am receiving the error below:
ModuleNotFoundError: No module named 'flask_session'
I believe I am importing the module properly, is there anything else that I can check to set this up properly?
from flask import Flask, render_template, request, session
from flask_session import Session
app = Flask(__name__)
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
#app.route("/", methods=["GET", "POST"])
def index():
if session.get("notes") is None:
session["notes"] = []
if request.method == "POST":
note = request.form.get("note")
session["notes"].append(note)
return render_template("index.html", notes=notes)
Here is the traceback ( most recent call last )
File "c:\python37\lib\site-packages\flask\cli.py", line 325, in __call__
Open an interactive python shell in this frameself._flush_bg_loading_exception()
File "c:\python37\lib\site-packages\flask\cli.py", line 313, in _flush_bg_loading_exception
reraise(*exc_info)
File "c:\python37\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "c:\python37\lib\site-packages\flask\cli.py", line 302, in _load_app
self._load_unlocked()
File "c:\python37\lib\site-packages\flask\cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "c:\python37\lib\site-packages\flask\cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "c:\python37\lib\site-packages\flask\cli.py", line 242, in locate_app
'\n\n{tb}'.format(name=module_name, tb=traceback.format_exc())
I've first encountered this problem while doing Harvard's CS50x class. I'm using Linux and I've been using Python3, as it turns out I've installed Flask-Session for Python2.
I don't know whether it also applies to Mac but I used the following instead:
$ pip3 install flask-session
Then you can check whether it's installed with pip's freeze command. After doing this my pylint in VSCode no longer gave an error.
I got the flask_session module not found a number of times and it took me 2 hours to find a fix after thousands of attempts. Well, I too visited a number of sites looking for a solution but didn't get any. I got this error while I was learning the online course cs50 web development on edx.org by Harvard and when I read the forum discussion on reddit I saw comments where they mentioned Harvard used a special server to make it work and I felt the pain of not going to Harvard but two hours later I'm screaming because I just found a solution that's no where on the internet.
You should not use from flask_session import Session
Instead use from flask_session.__init__ import Session
I cannot explain the terminology as to why we do this here but you can private message me if you want to understand why we do this. Happy Coding!
Be sure to have the extension installed:
pip install Flask-Session
oficial page with instructions
If you get the error "ModuleNotFoundError: No module named 'werkzeug.contrib'":
pip install werkzeug==0.16.0
The latest version is the 1.0.1 but only the 0.16.0 worked.
(where I found this solution) (official page)
simply goto terminal and type pip install flask_session , wait for installation, once done you are good to go. ( Also many other solutions do not work, look for red highlighted part in image. Once installed it works properly.)
I ran into the same error.
The following worked for me.
Install the extension with the following command:
$ easy_install Flask-Session
or alternatively, if you have pip installed:
$ pip install Flask-Session
I got it for windows:
There's no the library "flask_session" (--is a directory--) in your directory ...venv\Lib\site-packages (virtual environment)
You just need copy it from C:\Users\your _user\AppData\Local\Programs\Python\Python37-32\Lib\site-packages
and then paste it in venv\Lib\site-packages or where you have installed your virtual environment. Thats it and sorry for my english, greetings from Medellin Colombia.
Try to do following command instead of all go to terminal and type
$ easy_install Flask-Session
If it shows an error,use sudo before it , If it shows any error please let me know also feel free to upvote
Install the extension first using the following command $ pip install Flask-Session. You can read more on flask-session via https://pythonhosted.org/Flask-Session/
For completeness, I will share my solution:
In my case installed everything with pip3 to make it work with python 3.7, only worked with vscode after uninstalling python 2 from the system and reopening vscode.
Are you using this library? https://pythonhosted.org/Flask-Session/
The docs suggest importing it this way: from flask.ext.session import Session
I'm trying to use the undocumented library uwhoisd and I cannot figure out how to successfully call the whois() function on the UWhois object.
I start the deamon by calling a file UwhoisDeamon.py with following content:
import uwhoisd
uwhoisd.main()
The argument I give to python is the *.ini file that was included in the extra directory when I downloaded the source code
Starting the deamon is successful with following output:
2016-04-21 19:00:19,830 INFO:uwhoisd Reading config file at
'/path/to/my/ini/uwhoisd.ini' 2016-04-21
19:00:19,838 INFO:uwhoisd Listen on 0.0.0.0:4243 2016-04-21
19:00:19,842 INFO:uwhoisd Caching activated [2016/04/21 17:00:19]
{diesel} WARNING|Starting diesel
Now I'm trying perform a whois on google.com by starting a separate python instance and I get slapped in the face (I reused this code):
from os import path
import uwhoisd
from uwhoisd.utils import make_config_parser
HERE = path.dirname(__file__)
def create_uwhois():
"""Prepare a UWhois object for testing."""
config = path.join(HERE, 'uwhoisd.ini')
parser = make_config_parser(uwhoisd.CONFIG, config)
uwhois = uwhoisd.UWhois()
uwhois.read_config(parser)
return uwhois
uwhois = create_uwhois()
# uwhois = uwhoisd.UWhois()
result = uwhois.whois("google.com")
print result
And here the result:
Traceback (most recent call last):
File "/home/user/.eclipse/org.eclipse.platform_3.8_155965261/plugins/org.python.pydev_3.9.0.201411111611/pysrc/pydevd.py", line 2183, in <module>
globals = debugger.run(setup['file'], None, None)
File "/home/user/.eclipse/org.eclipse.platform_3.8_155965261/plugins/org.python.pydev_3.9.0.201411111611/pysrc/pydevd.py", line 1622, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/path/to/my/project/Whois/WhoisChecker.py", line 17, in <module>
result = uwhois.whois("google.com")
File "/usr/local/lib/python2.7/dist-packages/uwhoisd/__init__.py", line 137, in whois
with net.WhoisClient(server, port) as client:
File "/usr/local/lib/python2.7/dist-packages/diesel/client.py", line 16, in __init__
ip = self._resolve(self.addr)
File "/usr/local/lib/python2.7/dist-packages/diesel/client.py", line 21, in _resolve
return resolve_dns_name(addr)
File "/usr/local/lib/python2.7/dist-packages/diesel/resolver.py", line 67, in resolve_dns_name
except (NotFound, Timeout):
File "/usr/local/lib/python2.7/dist-packages/diesel/util/lock.py", line 24, in __exit__
self.release()
File "/usr/local/lib/python2.7/dist-packages/diesel/util/lock.py", line 18, in release
fire(self)
File "/usr/local/lib/python2.7/dist-packages/diesel/core.py", line 92, in fire
return current_loop.fire(*args, **kw)
AttributeError: 'NoneType' object has no attribute 'fire'
It seems to me that the diesel library which is used by uwhoisd to communicate between client and deamon application requires some special conditions to make it work. From what I can see the mysterious current_loop is not running. However I never used diesel before and I have no idea what to do. It seems to me that I have to somehow start that diesel loop before I can perform those whois queries.
A working example would be great. The main reason why I'm choosing uwhoisd is that I can perform whois on exotic websites such as "win.win". It also caches responses which means more speed and less network.
Author of uwhoisd here.
First up, get rid of UwhoisDeamon.py: it's a daemon, not a library. You're meant to run the daemon and then query it with a whois client. You don't have to write any additional code to get it up and running. It already installs a working console script that does the right thing.
When you install it, say, into a virtual environment, it will create a script called uwhoisd that you use to run the daemon. Here's an example:
$ virtualenv env
$ env/bin/pip install uwhoisd
Downloading/unpacking uwhoisd
Downloading uwhoisd-0.0.7-py2-none-any.whl
... installation log ...
Successfully installed uwhoisd diesel greenlet twiggy pyopenssl flask http-parser dnspython six cryptography Werkzeug Jinja2 itsdangerous idna pyasn1 setuptools enum34 ipaddress cffi MarkupSafe pycparser
Cleaning up...
If you run the daemon without, here's what you should get, assuming you had all the necessary system packages installed:
$ env/bin/uwhoisd
Usage: uwhoisd <config>
uwhoisd requires a configuration file that tells it how to talk to the various WHOIS servers it needs to be able to query. You can download the file like so:
$ wget https://raw.githubusercontent.com/kgaughan/uwhoisd/master/extra/uwhoisd.ini
Running the daemon with this config file should give you the following:
$ env/bin/uwhoisd uwhoisd.ini
2016-05-03 17:41:25,028 INFO:uwhoisd Reading config file at 'uwhoisd.ini'
2016-05-03 17:41:25,038 INFO:uwhoisd Listen on 0.0.0.0:4243
2016-05-03 17:41:25,058 INFO:uwhoisd Caching activated
The second line indicates what address and port the daemon is running on. In this case, it's running on all interfaces on port 4243, so you can now issue requests to it on that port (in a different terminal window):
$ whois -h localhost -p 4243 stackoverflow.com
Domain Name: STACKOVERFLOW.COM
Registry Domain ID: 108907621_DOMAIN_COM-VRSN
...
And you should see the following additional log lines in the terminal the daemon is running in:
2016-05-03 17:43:36,841 INFO:uwhoisd Querying whois.verisign-grs.com about stackoverflow.com
2016-05-03 17:43:37,283 INFO:uwhoisd Recursive query to whois.name.com about stackoverflow.com
You shouldn't be using uwhois's internals directly: it's a daemon and isn't designed to be used as a library, certainly not outside of diesel's event loop like that, which is why you got that traceback. Run the daemon with the config file, however, and you'll be golden.
Unfortunately, I haven't had time to write all the documentation for the daemon it needs, but I'm hoping to resolve this soon.
Good day,
I'm a student and I would just like to ask for a minute of your time.
I'm working on a barcode reader connected via USB port to a board name Arduino Yun. This board runs a version of embedded linux derived from OpenWrt using a microprocessor named Atheros AR9331
I would like to ask you, what's necessary to make the Python Evdev binding (python-evdev.readthedocs.org/en/latest/), to be able to run in this type of MIPS microarchitecture? At the momento, it's only for Ubuntu and ArchLinux.
I'm kind of guessing that cross compilation would be needed, or the indication of the usage of a specific C compiler inside this linux.
The current python version supported for OpenWrt is 2.7.3
I already know , if you compile C code in your PC, the resulting executable will only run in this type of architecture. If you use that compiled program inside the microprocessor, it wont work.
I've used this binding without trouble within ubuntu in my PC. I followed the instructions, python setup.py install, with a previous installation of setuptools, and it worked just fine.
But regarding OpenWrt, this was not the case.
The python script I'm using requires this library within the first line of code in order to reach the data from the device (it works like a keyboard /dev/input/event0):
#!/usr/bin/env python
from evdev import InputDevice, ecodes, list_devices
from select import select
I've seen suggestions of copying the entire library inside the arduino, and run the script inside the same folder. But it doesn't work, since the evdev module has files created with the architecture of the PC and not the MIPS.
So, what are the messages displayed for the error?
If you run python setup.py install in Openwrt to try to install the evdev binding, this appears on screen:
File "setup.py", line 10, in <module>
from setuptools.command.develop import develop
ImportError: No module named setuptools.command.develop
It's obvious from here that you need the module aforementioned. So, I tried to install it with this script (pypi.python.org/pypi/setuptools):
python ez_setup.py
And the output shows this:
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-11.3.1.zip
Traceback (most recent call last):
File "ez_setup.py", line 332, in <module>
sys.exit(main())
File "ez_setup.py", line 327, in main
downloader_factory=options.downloader_factory,
File "ez_setup.py", line 287, in download_setuptools
downloader(url, saveto)
File "ez_setup.py", line 209, in download_file_curl
_clean_check(cmd, target)
File "ez_setup.py", line 169, in _clean_check
subprocess.check_call(cmd)
File "/usr/lib/python2.7/subprocess.py", line 511, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['curl','https://pypi.python.org/packages/source/s/setuptools/setuptools-11.3.1.zip', '--silent', '--output', '/mnt/sda1/evdev-0.4.6/setuptools-11.3.1.zip']' returned non-zero exit status 60
I pressume this output is due to the fact that pypi doesn't exist for the python 2.7.3 in OpenWrt , only for newer versions and other architectures. Evedv binding is requiring the setuptools module in order to make things easier and standard, but if the binding is not supported for the target architecture, what's needed to be able to use it anyways?
Thanks for your time,
Good day everyone,
The solution was provided by Georgi Valkov. He is the creator of the python-evdev binding. I contacted him directly, and he was so kind that he cross compiled a version for the OpenWrt / Yun .
You can install the package using the openwrt package manager - opkg. The installation process is along the lines of:
$ opkg update
$ opkg install /path/to/python-evdev_0.4.7-1_ar71xx.ipk
To verify that the install was successful:
$ opkg files python-evdev
/usr/lib/python2.7/site-packages/evdev-0.4.7-py2.7.egg-info
/usr/lib/python2.7/site-packages/evdev/genecodes.py
/usr/lib/python2.7/site-packages/evdev/ff.py
/usr/lib/python2.7/site-packages/evdev/_input.so
/usr/lib/python2.7/site-packages/evdev/device.py
/usr/lib/python2.7/site-packages/evdev/events.py
/usr/lib/python2.7/site-packages/evdev/__init__.py
/usr/lib/python2.7/site-packages/evdev/ecodes.py
/usr/lib/python2.7/site-packages/evdev/_ecodes.so
/usr/lib/python2.7/site-packages/evdev/util.py
/usr/lib/python2.7/site-packages/evdev/uinput.py
/usr/lib/python2.7/site-packages/evdev/_uinput.so
This works just fine. Thanks.
PS. If someone needs the file, please contact me. Georgi sent me this address, but I didn't download the file from there because he sent it to me over email.
https://github.com/gvalkov/openwrt-packages-yun/blob/master/lang/python-evdev/Makefile
In the output, you can see that curl returned the status code 60. According to man curl
60 Peer certificate cannot be authenticated with known CA certifiā
cates.
According to the setuptools page, you can instead use python ez_setup.py --insecure but obviously do that at your own risk. Alternatively you could do what the advanced instructions say and manually download the setuptools tarball, verify its md5 hash yourself, and install it using its setup.py .