I'm tring to launch simple code from the docs:
https://flask-superadmin.readthedocs.org/en/latest/quickstart.html
Here is the code:
from flask import Flask
from flask.ext.superadmin import Admin
app = Flask(__name__)
admin = Admin(app)
app.run()
but the following error occures:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from flask.ext.superadmin import Admin
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask/exthook.py", line 62, in load_module
__import__(realname)
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask_superadmin/__init__.py", line 2, in <module>
from model import ModelAdmin
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask_superadmin/model/__init__.py", line 1, in <module>
from .base import ModelAdmin, AdminModelConverter
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 10, in <module>
from flask_superadmin.form import BaseForm, ChosenSelectWidget, DatePickerWidget, \
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask_superadmin/form.py", line 115, in <module>
class FileField(wtf.FileField):
AttributeError: 'module' object has no attribute 'FileField'
I use the following versions of libraries:
Flask==0.10.1
Flask-Script==0.6.2
Flask-SuperAdmin==1.7
Flask-WTF==0.9.1
flask-mongoengine==0.7.0
WTForms==1.0.4
What is wrong, or where could I find working examples?
This is a bug in the import. I fixed it in my fork; clone from there and then try it again.
Related
I'm trying to use flask-ask library and develope a skill that can make me able to control a robot in ROS with alexa vocal assistant. Python code named "alexa_interface.py" is here.
The skill id number is substituted with my skill id number.
While launching this command
python3 alexa_interface.py
I am getting the following code error.
Tried to install dependencies with pip but getting:
AttributeError: module 'lib' has no attribute 'ERR_load_RAND_strings'
Also notice that I am getting this error everytime I use pip to install something. Is pip broken? How can I adjust this?
Thank you.
#! /usr/bin/env python3
from flask import Flask
from ask_sdk_core.skill_builder import SkillBuilder
from flask_ask_sdk.skill_adapter import SkillAdapter
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.utils import is_request_type, is_intent_name
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model import Response
from ask_sdk_model.ui import SimpleCard
app = Flask(__name__)
class LaunchRequestHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_request_type("LaunchRequest")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Ciao, come posso aiutarti?"
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response`
skill_builder = SkillBuilder()
# Register your intent handlers to the skill_builder object
skill_builder.add_request_handler(LaunchRequestHandler())
skill_adapter = SkillAdapter(
skill=skill_builder.create(), skill_id="my-skill-id", app=app)
skill_adapter.register(app=app, route="/")
if __name__=='__main__':
app.run()
```
```
Traceback (most recent call last):
File "alexa_interface.py", line 2, in <module>
from flask import Flask
File "/home/toti/.local/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
ImportError: cannot import name 'escape' from 'jinja2' (/home/toti/.local/lib/python3.8/site-packages/jinja2/__init__.py)
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 32, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 12, in <module>
import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket
File "/usr/lib/python3/dist-packages/requests_unixsocket/__init__.py", line 1, in <module>
import requests
File "/home/toti/.local/lib/python3.8/site-packages/requests/__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/home/toti/.local/lib/python3.8/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/home/toti/.local/lib/python3.8/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/home/toti/.local/lib/python3.8/site-packages/OpenSSL/rand.py", line 213, in <module>
_lib.ERR_load_RAND_strings()
AttributeError: module 'lib' has no attribute 'ERR_load_RAND_strings'
Original exception was:
Traceback (most recent call last):
File "alexa_interface.py", line 2, in <module>
from flask import Flask
File "/home/toti/.local/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
ImportError: cannot import name 'escape' from 'jinja2' (/home/toti/.local/lib/python3.8/site-packages/jinja2/__init__.py)
```
I'm having some issues running checkov, I'm not familiar with python libraries, anyone can give me some hints?
This is working fine in some machines but not in this one in particular...
Running in CentOS:
$ checkov --directory cdk.out
Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in <module>
from checkov.main import run
File "/usr/local/lib/python3.6/site-packages/checkov/main.py", line 22, in <module>
from checkov.terraform.plan_runner import Runner as tf_plan_runner
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/plan_runner.py", line 11, in <module>
from checkov.terraform.context_parsers.registry import parser_registry
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/context_parsers/__init__.py", line 1, in <module>
from checkov.terraform.context_parsers.parsers import *
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/context_parsers/parsers/provider_context_parser.py", line 1, in <module>
import hcl2
File "/usr/local/lib/python3.6/site-packages/hcl2/__init__.py", line 5, in <module>
from .api import load, loads
File "/usr/local/lib/python3.6/site-packages/hcl2/api.py", line 4, in <module>
from hcl2.parser import hcl2
File "/usr/local/lib/python3.6/site-packages/hcl2/parser.py", line 53, in <module>
hcl2 = Lark_StandAlone(transformer=DictTransformer())
File "/usr/local/lib/python3.6/site-packages/hcl2/lark_parser.py", line 8, in Lark_StandAlone
return Lark._load_from_dict(DATA, MEMO, **kwargs)
AttributeError: type object 'Lark' has no attribute '_load_from_dict'
After upgrading python from 3.6 to 3.8 and reinstalling checkov it worked just fine.
I am learning and building a chatterbot with Python. I start with writing a simple chattbox. When I run the code, it errors out.
I am using Python 3.8.5, chatterbot 1.0.4 and Atom IDE
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot('Javis')
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train("chatterbot.corpus.english")
response = chatbot.get_response("Hello, how are you today?")
print(response)
When I run the code on Atom platformio-ide-terminal, it throws an error
Traceback (most recent call last):
File "chatbot.py", line 4, in <module>
chatbot = ChatBot('Bon')
File "C:\Python\Python38-32\lib\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Python\Python38-32\lib\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Python\Python38-32\lib\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
from sqlalchemy import create_engine
File "C:\Python\Python38-32\lib\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
File "C:\Python\Python38-32\lib\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
from ._collections import coerce_generator_arg # noqa
File "C:\Python\Python38-32\lib\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
from .compat import binary_types
File "C:\Python\Python38-32\lib\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
The function time.clock is deprecated since 3.3 version of python. Please check here for reference AttributeError: module 'time' has no attribute 'clock' in Python 3.8 , might be useful.
I'm new to Python and I'm trying to do a simple thread as follows.
import threading
def func(x):
print x
t1 = threading.Thread(target=func,args=("Hello",));
t1.start();
Then I got following error:
Traceback (most recent call last):
File "ex2.py", line 1, in <module>
import threading
File "/Users/treinetic-macbook/Desktop/threading.py", line 2, in <module>
File "/Library/Python/2.7/site-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/Library/Python/2.7/site-packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/Library/Python/2.7/site-packages/urllib3/connectionpool.py", line 3, in <module>
import logging
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 207, in <module>
_lock = threading.RLock()
AttributeError: 'module' object has no attribute 'RLock'
can someone help me to understand this error?
/Users/treinetic-macbook/Desktop/threading.py is being imported because it's on your path somewhere. This is most likely not correct, try renaming that file and removing any threading.pyc file in your local dir.
I'm experimenting with Page extensions and FeinCMS 1.2.1.
I'd like to create this simple page extension:
from django.db import models
def register(cls, admin_cls):
cls.add_to_class(models.TextField())
but I keep getting this error:
AttributeError: 'module' object has no attribute 'TextField'
The package containing the extension is called dev.extensions and the module categories, I have added it to the Python path and the extension is registered with Page.register_extensions('dev.extensions.categories').
I'm wondering what I'm doing wrong, please help.
The complete stacktrace follows.
c:\sandbox\projects\feindev>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_manager(settings)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 436, in execute_m
anager
setup_environ(settings_mod)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 419, in setup_env
iron
project_module = import_module(project_name)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "c:\sandbox\projects\feindev\..\fein
dev\__init__.py", line 52, in <module>
Page.register_extensions('dev.extensions.types')
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\models.py", line 270, in register_extensions
cls.register_extension(fn)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\module\page\models.py", line 564, in register_exten
sion
register_fn(cls, PageAdmin)
File "c:\sandbox\projects\feindev\dev\ext
ensions\types\__init__.py", line 4, in register
cls.add_to_class(models.TextField())
AttributeError: 'module' object has no attribute 'TextField'
Maybe models is getting reassigned somewhere to another module before your register function gets run?
Try changing your code to this:
from django.db import models as django_models
def register(cls, admin_cls):
cls.add_to_class('field_name_here', django_models.TextField())