I've tried to configurate pre-commit + mypy + django-stubs, so I have error when i try to commit.
ModuleNotFoundError: No module named 'environ'
My configs:
.pre-commit-config.yaml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: ''
hooks:
- id: mypy
exclude: "[a-zA-Z]*/(migrations)/(.)*"
args: [--config=setup.cfg,
--no-strict-optional,
--ignore-missing-imports]
additional_dependencies: [django-stubs]
setup.cfg
[mypy]
allow_redefinition = True
check_untyped_defs = True
ignore_missing_imports = True
incremental = True
strict_optional = True
show_traceback = True
warn_no_return = False
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
plugins = mypy_django_plugin.main
show_column_numbers = True
[mypy.plugins.django-stubs]
django_settings_module = config.settings.local
[mypy_django_plugin]
ignore_missing_model_attributes = True
[mypy-*.migrations.*]
# Django migrations should not produce any errors:
ignore_errors = True
It's look like mypy ignore option ignore_missing_imports = True.
Does anyone have any ideas?
Full error trace:
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/**/.cache/pre-commit/patch1646008720-58913.
[WARNING] The 'rev' field of repo 'https://github.com/pre-commit/mirrors-mypy' appears to be a mutable reference (moving tag / branch). Mutable references are never updated after first install and are not supported. See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details. Hint: `pre-commit autoupdate` often fixes this.
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...............................................................Passed
black....................................................................Passed
isort....................................................................Passed
dotenv-linter........................................(no files to check)Skipped
yamllint.................................................................Passed
flake8...................................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
Error constructing plugin instance of NewSemanalDjangoPlugin
Traceback (most recent call last):
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/mypy/__main__.py", line 12, in console_entry
main(None, sys.stdout, sys.stderr)
File "mypy/main.py", line 96, in main
File "mypy/main.py", line 173, in run_build
File "mypy/build.py", line 180, in build
File "mypy/build.py", line 231, in _build
File "mypy/build.py", line 478, in load_plugins
File "mypy/build.py", line 456, in load_plugins_from_config
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/mypy_django_plugin/main.py", line 143, in __init__
self.django_context = DjangoContext(django_settings_module)
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/mypy_django_plugin/django/context.py", line 95, in __init__
apps, settings = initialize_django(self.django_settings_module)
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/mypy_django_plugin/django/context.py", line 77, in initialize_django
settings._setup()
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 71, in _setup
self._wrapped = Settings(settings_module)
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 179, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/**/project/config/settings/local.py", line 3, in <module>
from .base import * # noqa
File "/home/**/project/config/settings/base.py", line 6, in <module>
import environ
ModuleNotFoundError: No module named 'environ'
I have to write some more text here, because stackoverflow get error: a lot of code, add details.
Related
I tried deploying my django/React (using postgreSQL) app using Render. The deploy worked but no data is being returned.
Also, when I try to load seed data or run the server from my directory the following error is thrown:
Traceback (most recent call last):
File "/Users/xxx/xxx/xxx/xxx/manage.py", line 22, in <module>
main()
File "/Users/xxx/xxx/xxx/xxx/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/xxx/.local/share/virtualenvs/xxx/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/Users/xxx/.local/share/virtualenvs/xxx/lib/python3.9/site-packages/django/core/management/__init__.py", line 386, in execute
settings.INSTALLED_APPS
File "/Users/xxx/.local/share/virtualenvs/xxx/lib/python3.9/site-packages/django/conf/__init__.py", line 87, in __getattr__
self._setup(name)
File "/Users/xxx/.local/share/virtualenvs/xxx/lib/python3.9/site-packages/django/conf/__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module)
File "/Users/xxx/.local/share/virtualenvs/xxx/lib/python3.9/site-packages/django/conf/__init__.py", line 183, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/xxx/xxx/xxx/xxx/project/settings.py", line 114, in <module>
'default': dj_database_url.parse(os.environ.get('DATABASE_URL'), conn_max_age=600),
File "/Users/xxx/.local/share/virtualenvs/xxx/lib/python3.9/site-packages/dj_database_url.py", line 94, in parse
if "?" in path and not url.query:
TypeError: a bytes-like object is required, not 'str'
Here's part of my settings.py:
DATABASES = {
'default': dj_database_url.parse(os.environ.get('DATABASE_URL'), conn_max_age=600),
}
I've also tried:
DATABASE_URL = os.environ.get('DATABASE_URL')
DATABASES = {
'default': dj_database_url.config()
}
But when I run the server, the app loads but has no data (just like the deployed app).
The code block surrounding line 94 in dj_database_url.py is as follows:
# Split query strings from path.
path = url.path[1:]
if "?" in path and not url.query:
path, query = path.split("?", 2)
else:
path, query = path, url.query
query = urlparse.parse_qs(query)
type(os.environ.get('DATABASE_URL')) returns <class 'NoneType'>
and the value returned for os.environ.get('DATABASE_URL') is None
I am using Elasticsearch APM in Python to log requests for a FastAPI app.
There is a mechanism to load custom processors by simply specifying the module path to the custom processor function.
My app layout is as follows:
app
├── __init__.py
├── apm_processors.py
├── main.py
└── version.py
My apm_processors.py file has the following function defined:
def ip_processor(client, event):
# process the event
pass
So, in my app, I do:
# other imports
from elasticapm.contrib.starlette import make_apm_client, ElasticAPM
from . import apm_processors
And to set up APM, I call:
apm_config = {
"SERVICE_NAME": config('ELASTIC_APM_SERVICE_NAME', cast=str, default="Server"),
"SECRET_TOKEN": str(config('ELASTIC_APM_SECRET_TOKEN', cast=Secret, default="")),
"SERVER_URL": config('ELASTIC_APM_SERVER_URL', cast=str, default="http://localhost:8200"),
"PROCESSORS": (
"elasticapm.processors.sanitize_http_request_cookies",
"elasticapm.processors.sanitize_http_headers",
"apm_processors.ip_processor"
)
}
apm = make_apm_client(apm_config)
app = FastAPI()
# other app setup
app.add_middleware(ElasticAPM, client=apm)
This throws an error:
ModuleNotFoundError: No module named 'apm_processors'
With the following stacktrace:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/usr/local/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.9/site-packages/uvicorn/subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "/usr/local/lib/python3.9/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "/usr/local/lib/python3.9/site-packages/uvicorn/server.py", line 67, in serve
config.load()
File "/usr/local/lib/python3.9/site-packages/uvicorn/config.py", line 458, in load
self.loaded_app = import_from_string(self.app)
File "/usr/local/lib/python3.9/site-packages/uvicorn/importer.py", line 24, in import_from_string
raise exc from None
File "/usr/local/lib/python3.9/site-packages/uvicorn/importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/statisticsserver/./app/main.py", line 75, in <module>
apm = make_apm_client(apm_config)
File "/usr/local/lib/python3.9/site-packages/elasticapm/contrib/starlette/__init__.py", line 70, in make_apm_client
return client_cls(config, **defaults)
File "/usr/local/lib/python3.9/site-packages/elasticapm/base.py", line 153, in __init__
"processors": self.load_processors(),
File "/usr/local/lib/python3.9/site-packages/elasticapm/base.py", line 640, in load_processors
return [seen.setdefault(path, import_string(path)) for path in processors if path not in seen]
File "/usr/local/lib/python3.9/site-packages/elasticapm/base.py", line 640, in <listcomp>
return [seen.setdefault(path, import_string(path)) for path in processors if path not in seen]
File "/usr/local/lib/python3.9/site-packages/elasticapm/utils/module_import.py", line 47, in import_string
module = import_module(module_path)
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'apm_processors'
As far as I can tell it uses import_module to import the function as specified, but for some reason it claims there is no such module — although I am actually able to import it.
How can I specify the processor?
Since the context/main module of the application is app, the import should be done as follows:
"PROCESSORS": (
"elasticapm.processors.sanitize_http_request_cookies",
"elasticapm.processors.sanitize_http_headers",
"app.apm_processors.ip_processor"
)
This way, the import succeeds and the function will be called for each event.
I am trying to use python-decouple for sensitive data in my project but
When i use decouple.config for SECRET_KEY it raises an error
error
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/admin/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/admin/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 345, in execute
settings.INSTALLED_APPS
File "/home/admin/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
self._setup(name)
File "/home/admin/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "/home/admin/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/admin/Legaland/src/sqh/settings/dev.py", line 1, in <module>
from ._base import *
File "/home/admin/Legaland/src/sqh/settings/_base.py", line 40, in <module>
SECRET_KEY = config("SECRET_KEY")
File "/home/admin/.local/lib/python3.6/site-packages/decouple.py", line 199, in __call__
return self.config(*args, **kwargs)
File "/home/admin/.local/lib/python3.6/site-packages/decouple.py", line 83, in __call__
return self.get(*args, **kwargs)
File "/home/admin/.local/lib/python3.6/site-packages/decouple.py", line 65, in get
value = self.repository[option]
File "/home/admin/.local/lib/python3.6/site-packages/decouple.py", line 113, in __getitem__
return self.parser.get(self.SECTION, key)
File "/usr/lib/python3.6/configparser.py", line 800, in get
d)
File "/usr/lib/python3.6/configparser.py", line 394, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/usr/lib/python3.6/configparser.py", line 444, in _interpolate_some
"found: %r" % (rest,))
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%^e=(r2l0*73)4zxv!(!4x(%(_koxr049zlesn3"'
How shall i make it read SECRET_KEY as text
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config("SECRET_KEY")
I am already I using .ini file for my email address and password the problem is that it tries to perform SECRET_KEY instead of accepting it as a raw text how can i prevent it
Right to the point, as said by Henrique Bastos, here:
Note: Since ConfigParser supports string interpolation, to represent the character % you need to escape it as %%.
To use python-decouple with a .ini file you can do this:
Use your variable like said in the first answer:
SECRET_KEY = config(SECRET_KEY, default='some-random-text')
You can use cast, if needed, like:
DEBUG = config(DEBUG, default=True, cast=bool)# in the .ini file, the DEBUG value can be: 0, 1, True, False...
So for last, your traceback error show that there is a percent sign in your .ini string value, you may need to do a scape with a %% as said in the official documentation https://github.com/henriquebastos/python-decouple
Do a escape parser with double percents, instead just one and the error will be gone!
you should have a env file like below
.env
SECRET_KEY='aaassskkkk'
and then source your .env file using below command
source .env
then try the below code it will works
from decouple import config
SECRET_KEY = config('SECRET_KEY', '')
if the SECRET_KEY not found in env it will take as ''
Decouple supports .ini and .env files. For use .env file simply create a .env text file in your repository's root directory.
SECRET_KEY='super-secret-key'
you can also override the parameter
SECRET_KEY='other-secret-key' python manage.py runserver
the title says all mostly, i'e been trying to make this package named chatterbot to work and then it shows this, i'm running ubuntu focal fossa
Full error log:
<frozen importlib._bootstrap>:219: RuntimeWarning: thinc.extra.search.Beam size changed, may indicate binary incompatibility. Expected 112 from C header, got 120 from PyObject
Traceback (most recent call last):
File "/home/arman/.local/lib/python3.8/site-packages/spacy/util.py", line 70, in get_lang_class
module = importlib.import_module(".lang.%s" % lang, "spacy")
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/arman/.local/lib/python3.8/site-packages/spacy/lang/en/__init__.py", line 15, in <module>
from ...language import Language
File "/home/arman/.local/lib/python3.8/site-packages/spacy/language.py", line 17, in <module>
from .pipeline import DependencyParser, Tagger
File "/home/arman/.local/lib/python3.8/site-packages/spacy/pipeline/__init__.py", line 4, in <module>
from .pipes import Tagger, DependencyParser, EntityRecognizer, EntityLinker
File "pipes.pyx", line 17, in init spacy.pipeline.pipes
File "/home/arman/.local/lib/python3.8/site-packages/spacy/pipeline/functions.py", line 4, in <module>
from ..matcher import Matcher
ModuleNotFoundError: No module named 'spacy.matcher'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 4, in <module>
bot = ChatBot('Test')
File "/usr/local/lib/python3.8/dist-packages/ChatterBot-1.1.0a7-py3.8.egg/chatterbot/chatterbot.py", line 28, in __init__
File "/usr/local/lib/python3.8/dist-packages/ChatterBot-1.1.0a7-py3.8.egg/chatterbot/utils.py", line 33, in initialize_class
File "/usr/local/lib/python3.8/dist-packages/ChatterBot-1.1.0a7-py3.8.egg/chatterbot/storage/sql_storage.py", line 20, in __init__
File "/usr/local/lib/python3.8/dist-packages/ChatterBot-1.1.0a7-py3.8.egg/chatterbot/storage/storage_adapter.py", line 22, in __init__
File "/usr/local/lib/python3.8/dist-packages/ChatterBot-1.1.0a7-py3.8.egg/chatterbot/tagging.py", line 26, in __init__
File "/home/arman/.local/lib/python3.8/site-packages/spacy/__init__.py", line 27, in load
return util.load_model(name, **overrides)
File "/home/arman/.local/lib/python3.8/site-packages/spacy/util.py", line 132, in load_model
return load_model_from_link(name, **overrides)
File "/home/arman/.local/lib/python3.8/site-packages/spacy/util.py", line 149, in load_model_from_link
return cls.load(**overrides)
File "/home/arman/.local/lib/python3.8/site-packages/spacy/data/en/__init__.py", line 12, in load
return load_model_from_init_py(__file__, **overrides)
File "/home/arman/.local/lib/python3.8/site-packages/spacy/util.py", line 196, in load_model_from_init_py
return load_model_from_path(data_path, meta, **overrides)
File "/home/arman/.local/lib/python3.8/site-packages/spacy/util.py", line 166, in load_model_from_path
cls = get_lang_class(lang)
File "/home/arman/.local/lib/python3.8/site-packages/spacy/util.py", line 72, in get_lang_class
raise ImportError(Errors.E048.format(lang=lang, err=err))
ImportError: [E048] Can't import language en from spacy.lang: No module named 'spacy.matcher'
I've tried all the other solutions on the internet none of them worked, it's been so many hours i don't even remember them all please forgive me
I don't Know what just happened or what was the problem but i fixed it, in case anyone encounters the issue i'll leave it here
Get spacy from github
Install everything on the requirements file
Install spacy from source
It's fixed somehow...
I'm currently working on a project that uses Twilio to have an automated survey. I'm trying python manage.py runserver and I get the following results:
System check identified no issues (0 silenced).
April 23, 2017 - 12:15:51
Django version 1.11, using settings 'vizeserver.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x04406FA8
>
Traceback (most recent call last):
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\uti
ls\autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\cor
e\management\commands\runserver.py", line 147, in inner_run
handler = self.get_handler(*args, **options)
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\con
trib\staticfiles\management\commands\runserver.py", line 27, in get_handler
handler = super(Command, self).get_handler(*args, **options)
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\cor
e\management\commands\runserver.py", line 68, in get_handler
return get_internal_wsgi_application()
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\cor
e\servers\basehttp.py", line 47, in get_internal_wsgi_application
return import_string(app_path)
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\uti
ls\module_loading.py", line 20, in import_string
module = import_module(module_path)
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py",
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\Thomas\Documents\Development\TwilioSurvey\vizeserver\vizeserver\wsgi.py", lin
e 16, in <module>
application = get_wsgi_application()
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\cor
e\wsgi.py", line 14, in get_wsgi_application
return WSGIHandler()
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\wsgi.py", line 151, in __init__
self.load_middleware()
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py", line 82, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters
I have looked into my vizeserver.settings and I don't see anything off.
The link for the github is https://github.com/Vize-Programming-Team/web-server. I've been trying to see if there is anything wrong with the middleware but I don't know what's wrong.
Thanks!
The problem is with your middleware, try changing your middleware.py in auto_survey to
class SMSMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
args = request.POST or request.GET
request.is_sms = args and args.get('MessageSid')
return response