console error output not showing the line with the error - python

Please I really need help, I do not know what could be going on in my program, initialy if there was an error it just simply point where an error is in
my code e.g.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\python_files\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\python_files\venv\lib\site-packages\channels\management\commands\runserver.py", line 75, in inner_run
self.check(display_num_errors=True)
File "C:\python_files\venv\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\python_files\venv\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\python_files\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\python_files\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\python_files\venv\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\python_files\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\python_files\venv\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\python_files\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\python_files\venv\lib\site-packages\django\urls\resolvers.py", line 582, in
urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\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 "C:\python_files\hospital_project\urls.py", line 61, in <module>
url('residence/', include('hospital_project.residence.urls', namespace="residence")),#dashboard for residence
File "C:\python_files\venv\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\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 "C:\python_files\hospital_project\residence\urls.py", line 36, in <module>
url(r'pharmacy1', views.pharmacy1, name="pharmacy"),
AttributeError: module 'hospital_project.residence.views' has no attribute 'pharmacy1'
from the above error it can be seen that the error is at file C:\python_files\hospital_project\residence\urls.py line 36
This has been the normal for a long time since I have been using python. But suddenly I discorvered that the output changed.
Instead of giving me the specific line in the file where the problem exist. It prints out the whole code in the pythong file onto the console.
See an example below.
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 1081, in emit
msg = self.format(record)
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 925, in format
return fmt.format(record)
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 672, in format
record.exc_text = self.formatException(record.exc_info)
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 622, in formatException
traceback.print_exception(ei[0], ei[1], tb, None, sio)
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\traceback.py", line 103, in print_exception
for line in TracebackException(
File "C:\software_development\python\venv\lib\site-packages\trio\_core\_multierror.py", line 393, in traceback_exception_init
traceback_exception_original_init(
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\traceback.py", line 523, in __init__
self._load_lines()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\traceback.py", line 535, in _load_lines
self.__context__._load_lines()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\traceback.py", line 535, in _load_lines
self.__context__._load_lines()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\traceback.py", line 535, in _load_lines
self.__context__._load_lines()
[Previous line repeated 6 more times]
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\traceback.py", line 533, in _load_lines
frame.line
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\traceback.py", line 288, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 47, in getlines
return updatecache(filename, module_globals)
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 137, in updatecache
lines = fp.readlines()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 6781: invalid start byte
Call stack:
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\threading.py", line 890, in _bootstrap
self._bootstrap_inner()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\software_development\python\venv\lib\site-packages\django\utils\autoreload.py", line 53, i
n wrapper
fn(*args, **kwargs)
File "C:\software_development\python\venv\lib\site-packages\channels\management\commands\runserver.py", line 106, in inner_run
self.server_cls(
File "C:\software_development\python\venv\lib\site-packages\daphne\server.py", line 143, in run
reactor.run(installSignalHandlers=self.signal_handlers)
File "C:\software_development\python\venv\lib\site-packages\twisted\internet\asyncioreactor.py", li
ne 255, in run
self._asyncioEventloop.run_forever()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 570, in run_forever
self._run_once()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 1859, in _run_once
handle._run()
File "C:\Users\software_developer\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "C:\software_development\python\venv\lib\site-packages\twisted\internet\asyncioreactor.py", li
ne 271, in _onTimer
self.runUntilCurrent()
File "C:\software_development\python\venv\lib\site-packages\twisted\internet\base.py", line 991, in
runUntilCurrent
call.func(*call.args, **call.kw)
File "C:\software_development\python\venv\lib\site-packages\daphne\server.py", line 290, in applica
tion_checker
logger.error(
Message: 'Exception inside application: %s'
Arguments: (UnicodeDecodeError('utf-8', b'import re\r\nfrom django.db.models import Count, Avg\r\nfrom django.shortcuts import render, redirect\r\nfrom django.http
import HttpResponse, HttpResponseRedirect, StreamingHttpResponse\r\n\r\nfrom django.urls import reverse...................the rest of the output are just my code
with \r \n \t included allover
please what could be going on and how can I get the program to produce error.
I would really appreciate any help thanks

The first line of your log tells that it's a problem with emit method in logging python library. So the problem is that logging cannot properly emit the message to your terminal. The reason is at the bottom:
File "C:\software_development\python\venv\lib\site-packages\daphne\server.py", line 290, in applica
tion_checker
logger.error(
Message: 'Exception inside application: %s'
Arguments: (UnicodeDecodeError('utf-8', b'
So the site-package daphne which is probably a Django dependency has a problem logging the message because the Arguments that it tries to logs cannot be decoded to UTF-8.
From this traceback and without the actual code it's hard to say what's the exact reason, but if I were you I'd just run the code with the debugger, execute code line by line and check where the issue is.
You know which file causes the problem, because as you wrote the entire content of the file is logged.
You should be cautious what do you actually log. Do you log some user input data? Some contents of DB which you can't exactly predict? Can there be any special, non UTF-8 characters?

Related

Python 3.11 installing repl-cli: setuptools not found even it's installed

That's it. I am installing repl-cli but it's giving "ModuleNotFoundError: No module named 'setuptools'".
I tried:
pip install setuptools
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: setuptools in /home/bitte/.local/lib/python3.11/site-packages (67.1.0)
And then:
pip install repl-cli
.
. Tons of installation verbose
.
RROR: Exception:
Traceback (most recent call last):
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/cli/base_command.py", line 160, in exc_logging_wrapper
status = run_func(*args)
^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
return func(self, options, args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/commands/install.py", line 415, in run
requirement_set = resolver.resolve(
^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 92, in resolve
result = self._result = resolver.resolve(
^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/resolvelib/resolvers.py", line 481, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/resolvelib/resolvers.py", line 373, in resolve
failure_causes = self._attempt_to_pin_criterion(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/resolvelib/resolvers.py", line 213, in _attempt_to_pin_criterion
criteria = self._get_updated_criteria(candidate)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/resolvelib/resolvers.py", line 204, in _get_updated_criteria
self._add_to_criteria(criteria, requirement, parent=candidate)
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/resolvelib/resolvers.py", line 172, in _add_to_criteria
if not criterion.candidates:
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/resolvelib/structs.py", line 151, in __bool__
return bool(self._sequence)
^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in __bool__
return any(self)
^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 47, in _iter_built
candidate = func()
^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 206, in _make_candidate_from_link
self._link_candidate_cache[link] = LinkCandidate(
^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 297, in __init__
super().__init__(
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 162, in __init__
self.dist = self._prepare()
^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 231, in _prepare
dist = self._prepare_distribution()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 308, in _prepare_distribution
return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/operations/prepare.py", line 491, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/operations/prepare.py", line 577, in _prepare_linked_requirement
dist = _get_prepared_distribution(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/operations/prepare.py", line 69, in _get_prepared_distribution
abstract_dist.prepare_distribution_metadata(
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/distributions/sdist.py", line 48, in prepare_distribution_metadata
self._install_build_reqs(finder)
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/distributions/sdist.py", line 118, in _install_build_reqs
build_reqs = self._get_build_requires_wheel()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/distributions/sdist.py", line 95, in _get_build_requires_wheel
return backend.get_requires_for_build_wheel()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_internal/utils/misc.py", line 701, in get_requires_for_build_wheel
return super().get_requires_for_build_wheel(config_settings=cs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 166, in get_requires_for_build_wheel
return self._call_hook('get_requires_for_build_wheel', {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 321, in _call_hook
raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Traceback (most recent call last):
File "/home/bitte/.local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
obj = import_module(mod_path)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'setuptools'
Just don't know what to do. I am this whole day trying to install packages and searching errors on google. I already solved at leats 7 error messages for installing this today and I can't fix this one alone.

running pytest does nothing

I created a python file for running pytest but whenever I run pytest nothing happens and command prompt stays as it is. But when I do Ctrl+C this following Traceback is printing. I couldn't find how to solve this issue. I will be grateful for any support you can provide.
File "C:\ProgramData\Anaconda3\lib\tempfile.py", line 255, in _mkstemp_inner
fd = _os.open(file, flags, 0o600)
PermissionError: [Errno 13] Permission denied: 'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\anyio\\__pycache__\\tmp7fewgyj8'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\Scripts\pytest-script.py", line 10, in <module>
sys.exit(console_main())
File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 187, in console_main
code = main()
File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 145, in main
config = _prepareconfig(args, plugins)
File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 324, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "C:\ProgramData\Anaconda3\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "C:\ProgramData\Anaconda3\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "C:\ProgramData\Anaconda3\lib\site-packages\pluggy\_callers.py", line 55, in _multicall
gen.send(outcome)
File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\helpconfig.py", line 102, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "C:\ProgramData\Anaconda3\lib\site-packages\pluggy\_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "C:\ProgramData\Anaconda3\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 1016, in pytest_cmdline_parse
self.parse(args)
File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 1304, in parse
self._preparse(args, addopts=addopts)
File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 1187, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "C:\ProgramData\Anaconda3\lib\site-packages\pluggy\_manager.py", line 287, in load_setuptools_entrypoints
plugin = ep.load()
File "C:\ProgramData\Anaconda3\lib\importlib\metadata.py", line 86, in load
module = import_module(match.group('module'))
File "C:\ProgramData\Anaconda3\lib\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 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
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 "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\assertion\rewrite.py", line 163, in exec_module
_write_pyc(state, co, source_stat, pyc)
File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\assertion\rewrite.py", line 315, in _write_pyc
with atomic_write(os.fspath(pyc), mode="wb", overwrite=True) as fp:
File "C:\ProgramData\Anaconda3\lib\contextlib.py", line 119, in __enter__
return next(self.gen)
File "C:\ProgramData\Anaconda3\lib\site-packages\atomicwrites\__init__.py", line 166, in _open
with get_fileobject(**self._open_kwargs) as f:
File "C:\ProgramData\Anaconda3\lib\site-packages\atomicwrites\__init__.py", line 183, in get_fileobject
descriptor, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
File "C:\ProgramData\Anaconda3\lib\tempfile.py", line 336, in mkstemp
return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
File "C:\ProgramData\Anaconda3\lib\tempfile.py", line 255, in _mkstemp_inner
fd = _os.open(file, flags, 0o600)```
Seems you dont have the right permissions as stated by #mrCopiCat, but you are on windows so you can do something like this.
import ctypes, sys
def elevate():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if elevate():
# Put your program here
else:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
Or better yet using elevate: https://pypi.org/project/elevate/

Python : 'Doc2Vec' object has no attribute 'dv'

Thanks for advice, I have edited the question
I meet this: AttributeError: 'Doc2Vec' object has no attribute 'dv'
The error comes from
Traceback (most recent call last):
File "F:\Projects\项目代码\爬虫程序\headline\main.py", line 13, in <module>
execute(["scrapy", "crawl", "head_spider", '-a', 'key='+sys.argv[1]])
File "C:\Python310\lib\site-packages\scrapy\cmdline.py", line 144, in execute
cmd.crawler_process = CrawlerProcess(settings)
File "C:\Python310\lib\site-packages\scrapy\crawler.py", line 290, in __init__
super().__init__(settings)
File "C:\Python310\lib\site-packages\scrapy\crawler.py", line 167, in __init__
self.spider_loader = self._get_spider_loader(settings)
File "C:\Python310\lib\site-packages\scrapy\crawler.py", line 161, in _get_spider_loader
return loader_cls.from_settings(settings.frozencopy())
File "C:\Python310\lib\site-packages\scrapy\spiderloader.py", line 67, in from_settings
return cls(settings)
File "C:\Python310\lib\site-packages\scrapy\spiderloader.py", line 24, in __init__
self._load_all_spiders()
File "C:\Python310\lib\site-packages\scrapy\spiderloader.py", line 51, in _load_all_spiders
for module in walk_modules(name):
File "C:\Python310\lib\site-packages\scrapy\utils\misc.py", line 88, in walk_modules
submod = import_module(fullpath)
File "C:\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "F:\Projects\项目代码\爬虫程序\headline\headline\spiders\head_spider.py", line 6, in <module>
from headline.items import Artical
File "F:\Projects\项目代码\爬虫程序\headline\headline\items.py", line 20, in <module>
model = Doc2Vec.load('D:/pyspace/headline/headline/utils/model3/doc2vec.model')
File "C:\Python310\lib\site-packages\gensim\models\doc2vec.py", line 813, in load
raise ae
File "C:\Python310\lib\site-packages\gensim\models\doc2vec.py", line 807, in load
return super(Doc2Vec, cls).load(*args, rethrow=True, **kwargs)
File "C:\Python310\lib\site-packages\gensim\models\word2vec.py", line 1937, in load
raise ae
File "C:\Python310\lib\site-packages\gensim\models\word2vec.py", line 1930, in load
model = super(Word2Vec, cls).load(*args, **kwargs)
File "C:\Python310\lib\site-packages\gensim\utils.py", line 486, in load
obj._load_specials(fname, mmap, compress, subname)
File "C:\Python310\lib\site-packages\gensim\models\word2vec.py", line 1946, in _load_specials
super(Word2Vec, self)._load_specials(*args, **kwargs)
File "C:\Python310\lib\site-packages\gensim\utils.py", line 517, in _load_specials
getattr(self, attrib)._load_specials(cfname, mmap, compress, subname)
File "C:\Python310\lib\site-packages\gensim\utils.py", line 1521, in new_func1
return func(*args, **kwargs)
File "C:\Python310\lib\site-packages\gensim\models\doc2vec.py", line 326, in docvecs
return self.dv
AttributeError: 'Doc2Vec' object has no attribute 'dv'
the 'D:/pyspace/headline/headline/utils/model3/doc2vec.model' is an model that has ever been trained.
gensim version is 4.1.2
Django version is 4.0.3
I don't know what should I do to solve this problem. Thanks for help
It may be the problem of your version, or you can try to correct your code "model.doc2vec"

NameError: name 'o' is not defined Error in django app

I have a problem with my Django app, I removed my products app for more practicing and when I use migrate or makemigrations code, I get this error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\commands\migrate.py", line 75, in handle
self.check(databases=[database])
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\clpxv\Desktop\Projects\venv\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\clpxv\AppData\Local\Programs\Python\Python38-32\lib\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 "C:\Users\clpxv\Desktop\Projects\Projects\urls.py", line 15, in <module>
o
NameError: name 'o' is not defined
I don't have any idea what is this, I didn't change anything in os or anything else.
I will be grateful for a simple answer.
You have typed 'o' in urls.py line 15 just remove and save the file and delete migration file and again migrate all details

Exception in thread django-main-thread

I was implementing google login by using oauth2client library and did some change in /google-login/myvenv/lib/python3.5/site-packages/oauth2client/contrib/django_util/__init__.py
just replaced from django.core import urlresolvers to from django.urls import reverse and Line 411 urlresolvers.reverse(...) to reverse(...)
While running my server
python manage.py runserver
A typeError occured
Trace back of this error is:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[0](_exception[1]).with_traceback(_exception[2])
TypeError: __init__() missing 2 required positional arguments: 'doc' and 'pos'
Got this traceback
I have no clue what does it mean.
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/akshay/django/google_login/myvenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
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/akshay/django/google_login/login/models.py", line 3, in <module>
from oauth2client.contrib.django_util.models import CredentialsField
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/oauth2client/contrib/django_util/__init__.py", line 365, in <module>
oauth2_settings = OAuth2Settings(django.conf.settings)
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/oauth2client/contrib/django_util/__init__.py", line 341, in __init__
info = _get_oauth2_client_id_and_secret(settings_instance)
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/oauth2client/contrib/django_util/__init__.py", line 277, in _get_oauth2_client_id_and_secret
return _load_client_secrets(secret_json)
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/oauth2client/contrib/django_util/__init__.py", line 255, in _load_client_secrets
client_type, client_info = clientsecrets.loadfile(filename)
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/oauth2client/clientsecrets.py", line 165, in loadfile
return _loadfile(filename)
File "/home/akshay/django/google_login/myvenv/lib/python3.6/site-packages/oauth2client/clientsecrets.py", line 122, in _loadfile
obj = json.load(fp)
File "/usr/lib/python3.6/json/__init__.py", line 299, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid control character at: line 1 column 451 (char 450)
There was a syntax error in my client_secrets.json file.
After fixing, it worked.
Thanks AKX for pointing out.
Try installing Postgres if you are using one.
If already installed try - pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start.

Categories

Resources