ImportError: cannot import name 'urlresolvers' from 'django.core' - django-models

Can anybody help figuring out the issue and solution.Here is the error for python 3.10.6 and django 3.2.17
python manage.py runserver 0.0.0.0:8001
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/home/mindmatrix/Documents/demo/lib/python3.10/site- packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/core/management/__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/apps/config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.10/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 "/home/mindmatrix/Documents/job_portal_updated_Feb_10/peeldb/models.py", line 8, in <module>
from oauth2client.contrib.django_util.models import CredentialsField
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/oauth2client/contrib/django_util/__init__.py", line 233, in <module>
from django.core import urlresolvers
ImportError: cannot import name 'urlresolvers' from 'django.core' (/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/core/__init__.py)
I am trying for version upgrade of the open source project. I have upgraded all the neccessary requirements for the project. Now while running the command python manage.py runserver I am facing this issue.If any one can help?? I`

Related

Having trouble with pyodbc on django

I am working on django project. And testing Sql Server database.
I am using korean linux hosting service gabia. So I don't have any root access.
Even this hosting company blocked yum and rpm.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libodbc.so.2: cannot open shared object file: No such file or directory
I am keep having this kind of trouble when I import pyodbc. But I can fully use pymssql module.
I have no idea what is wrong with this linux...
This is when I connect django to mssql database with mssql-django package.
Traceback (most recent call last):
File "/web/.local/lib/python3.9/site-packages/mssql/base.py", line 16, in <module>
import pyodbc as Database
ImportError: libodbc.so.2: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/web/.local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 130, in __call__
signals.request_started.send(sender=self.__class__, environ=environ)
File "/web/.local/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 176, in send
return [
File "/web/.local/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 177, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "/web/.local/lib/python3.9/site-packages/django/db/__init__.py", line 46, in reset_queries
for conn in connections.all():
File "/web/.local/lib/python3.9/site-packages/django/utils/connection.py", line 76, in all
return [self[alias] for alias in self]
File "/web/.local/lib/python3.9/site-packages/django/utils/connection.py", line 76, in <listcomp>
return [self[alias] for alias in self]
File "/web/.local/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/web/.local/lib/python3.9/site-packages/django/db/utils.py", line 208, in create_connection
backend = load_backend(db["ENGINE"])
File "/web/.local/lib/python3.9/site-packages/django/db/utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
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 "/web/.local/lib/python3.9/site-packages/mssql/base.py", line 18, in <module>
raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: libodbc.so.2: cannot open shared object file: No such file or directory
This linux is CentOS 7
I've tried to install unixODBC on /web/.local directory which I can access into. And I successfully executed unixodbc alone, but not with python pyodbc.
I failed to install FreeTDS because I cannot find any way to install FreeTDS on this linux with tar file.
I wonder if I can change the installation path written on pyodbc package file. If I can, then I can fix this problem with changing the installation root of unixODBC to my accessable directory.

Module Not Found Error while trying to make migrations in app django "No module named 'app'"

So I keep hitting this error when I try to make migrations after effecting changes in my models.py
(.venv) C:\Users\MR UWZX\Desktop\Zuri_tasks>python manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\MR UWZX\Desktop\Zuri_tasks\manage.py", line 22, in <module>
main()
File "C:\Users\MR UWZX\Desktop\Zuri_tasks\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\MR UWZX\Desktop\Zuri_tasks\.venv\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\MR UWZX\Desktop\Zuri_tasks\.venv\lib\site-packages\django\core\management\__init__.py", line 420, in execute
django.setup()
File "C:\Users\MR UWZX\Desktop\Zuri_tasks\.venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\MR UWZX\Desktop\Zuri_tasks\.venv\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry) File "C:\Users\MR UWZX\Desktop\Zuri_tasks\.venv\lib\site-packages\django\apps\config.py", line 178, in create
mod = import_module(mod_path)
File "C:\Users\MR UWZX\AppData\Local\Programs\Python\Python310-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050,0,n _gcd_import
in _gcd_import 7,
File "<frozen importlib._bootstrap>", line 1027,File "<frozen importlib._bootstrap>", line 992, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, , _call_with_frames_removed
in _find_and_load_unlocked 0,
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import 7,
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load 4,
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'musicapp'
I've tried deleting my database and pycache nothing works! I'd attach my models, settings and apps.py below.[[enter image description here](https://i.stack.imgur.com/JnuYa.jpg)](https://i.stack.imgur.com/4BDFt.jpg)
I've tried used Musicapp.Config as the app name but it still gives errors.

ModuleNotFoundError: No module named 'google.cloud.location'

We have an application that uses firestore. It is running on Python 3.x on standard Google app engine. The application was running fine, till this morning when we tried to run the new version. The deployment of the new version is executed without any error. The requirement.txt is as follows -
firebase_admin==3.0.0
sendgrid==6.9.3
google-auth==1.35.0
google-auth-httplib2==0.1.0
jinja2==3.0.3
MarkupSafe==2.0.1
pytz==2021.3
Flask==2.0.2
twilio==6.46.0
httplib2==0.20.2
requests==2.24.0
requests_toolbelt==0.9.1
google-cloud-tasks==2.7.1
google-cloud-logging==1.15.1
googleapis-common-protos==1.54.0
protobuf==3.20.1
We get the following error.
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/services/firestore/client.py", line 55, in <module>
from google.cloud.location import locations_pb2 # type: ignore
ModuleNotFoundError: No module named 'google.cloud.location'
Please help.
Updated (9-24-2022) with the complete error output.
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
super().init_process()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/opt/python3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/srv/main.py", line 8, in <module>
from controllers import server, common, header
File "/srv/controllers/server.py", line 19, in <module>
from controllers import basehandler
File "/srv/controllers/basehandler.py", line 12, in <module>
from google.cloud import firestore
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore/__init__.py", line 18, in <module>
from google.cloud.firestore_v1 import __version__
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/__init__.py", line 36, in <module>
from google.cloud.firestore_v1.async_client import AsyncClient
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/async_client.py", line 45, in <module>
from google.cloud.firestore_v1.async_transaction import AsyncTransaction
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/async_transaction.py", line 49, in <module>
from google.cloud.firestore_v1.client import Client
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/client.py", line 44, in <module>
from google.cloud.firestore_v1.services.firestore import client as firestore_client
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/services/firestore/__init__.py", line 16, in <module>
from .client import FirestoreClient
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/services/firestore/client.py", line 55, in <module>
from google.cloud.location import locations_pb2 # type: ignore
ModuleNotFoundError: No module named 'google.cloud.location'
It looks like Google made a mistake in setting requirements for one its Python packages.
If you create a new virtual environment, install with pip install -r you should be able to recreate the error you are seeing in production.
To fix it, I would do pip list on your local machine (in the environment that is still working) and add fixed versions of other installed google packages until it works.
You can test by creating a new Python virtual environment, installing with pip install -r and seeing if it works.
It is a tedious process unfortunately.
I got this exact same error just now while trying to link a Python script to Firestore. I don't know if this is a "correct" solution but I got my code to run and save data to my Firestore database after this doing this.
In the error message, this line specifies the file where google.cloud.location is being imported:
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/google/cloud/firestore_v1/services/firestore/client.py", line 55, in <module>
If you open the client.py file and comment out the line 55 ("from google.cloud.location import locations_pb2 # type: ignore"), then run your code again, the next error message will show the other file where google.cloud.location is being imported. Repeat this process for all five files where this module is imported. (client.py, base.py, grpc.py, grpc_asyncio.py, async_client.py)
From searching through the code, I'm seeing that locations_pb2 (imported from google.cloud.location) is never used. I suspect that commenting this out entirely won't affect the functionality of firebase_admin.

Can't seem to make the makemigration work

model.py:
from django.db import models
# Create your models here.
class Departments(models.Model):
DepartmentId = models.AutoField(primary_key=True)
DepartmentName = models.CharField(max_length=500)
class Employees(models.Model):
EmployeesId = models.AutoField(primary_key=True)
EmployeesName = models.CharField(max_length=500)
Department = models.CharField(max_length=500)
DateOfJoining = models.DateField()
PhotoFileName = models.CharField(max_length=500)
cmd:
Microsoft Windows [Version 10.0.19042.1052]
(c) Microsoft Corporation. All rights reserved.
C:\tutorial\api\DjangoAPI>python manage.py makemigrations EmployeeApp
Traceback (most recent call last):
File "C:\tutorial\api\DjangoAPI\manage.py", line 22, in <module>
main()
File "C:\tutorial\api\DjangoAPI\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\config.py", line 212, in create
mod = import_module(mod_path)
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\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 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'Employee'
C:\tutorial\api\DjangoAPI>
Im not sure why its not working because i found similar tutorials online and every other line was similar to mine. I always get the error; "No module named 'Employee' when i try running the server.
Thank you inadvance.

Connecting django to MS SQL Server using odbc

I'm getting an error when trying to execute manage.py runserver. I've installed django-pyodbc and the odbc driver 17 for sql server. Do I need to import pyodbc somewhere in the project? I am very new to django and python in general but I want to use ms sql server instead of sqlite. This is the code in manage.py:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'database',
'HOST': 'localhost',
'USER': 'user',
'PASSWORD': 'password',
'OPTIONS': {'ODBC Driver 17 for SQL Server',
}
}
}
Here is the error:
(venv) C:\Users\Kirk\PycharmProjects\PyShop>manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001770CD61438>
Traceback (most recent call last):
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\core\management\__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Kirk\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\models\base.py", line 101, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\models\base.py", line 305, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\models\options.py", line 203, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\utils.py", line 203, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\sql_server\pyodbc\base.py", line 193, in __init__
self.driver_charset = opts.get('driver_charset', None)
AttributeError: 'set' object has no attribute 'get
'
Any help is appreciated. Thank you.
Change your options to following. Error might be caused by string parsing function of pyodbc library.
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
}
or
‘OPTIONS’: {“ODBC Driver 17 for SQL Server”, }

Resources