ImportError: cannot import name Connection while adding session? - python

I have a django project working fine . now i need to add login with session on that project I use mango .
As added in setting.py file
SESSION_ENGINE = 'mango.session'
then it started to give following error:
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 170, in __call__
self.load_middleware()
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 52, in load_middleware
mw_instance = mw_class()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/middleware.py", line 11, in __init__
engine = import_module(settings.SESSION_ENGINE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/shubham/Music/ekomerz/mango/__init__.py", line 2, in <module>
from pymongo import Connection
ImportError: cannot import name Connection
how I can solve this ?
and is there is any other method should i try for login with session ?

Related

"32 - Could not authenticate you." error in tweepy

I was working with tweepy with Django and the code was working fine.
But, when I deployed the code on railway (similar to Heroku), the app showed these logs:
File "/app/tweet_scrapper/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/opt/venv/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/opt/venv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/venv/lib/python3.9/site-packages/django/apps/registry.py", line 124, in populate
app_config.ready()
File "/app/tweets/apps.py", line 10, in ready
from . import jobs
File "/app/tweets/jobs.py", line 85, in <module>
scrap()
File "/app/tweets/jobs.py", line 69, in scrap
searched_tweets = api.search_tweets(
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 33, in wrapper
return method(*args, **kwargs)
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 1309, in search_tweets
return self.request(
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 263, in request
raise Unauthorized(resp)
tweepy.errors.Unauthorized: 401 Unauthorized
32 - Could not authenticate you.
Traceback (most recent call last):
File "/opt/venv/lib/python3.9/site-packages/gunicorn/arbiter.py", line 502, in spawn_worker
worker.init_process()
File "/opt/venv/lib/python3.9/site-packages/gunicorn/workers/base.py", line 114, in init_process
self.wsgi = self.app.wsgi()
File "/opt/venv/lib/python3.9/site-packages/gunicorn/app/base.py", line 66, in wsgi
self.callable = self.load()
File "/opt/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/opt/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/opt/venv/lib/python3.9/site-packages/gunicorn/util.py", line 356, in import_app
__import__(module)
File "/app/tweet_scrapper/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/opt/venv/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/opt/venv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/venv/lib/python3.9/site-packages/django/apps/registry.py", line 124, in populate
app_config.ready()
File "/app/tweets/apps.py", line 10, in ready
from . import jobs
File "/app/tweets/jobs.py", line 85, in <module>
scrap()
File "/app/tweets/jobs.py", line 69, in scrap
searched_tweets = api.search_tweets(
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 33, in wrapper
return method(*args, **kwargs)
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 1309, in search_tweets
return self.request(
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 263, in request
raise Unauthorized(resp)
tweepy.errors.Unauthorized: 401 Unauthorized
32 - Could not authenticate you.
It was working fine locally.
I have elevated access to Twitter API.
I checked all the keys and tokens, and they're correct (but I'm accessing them from environment variables).
My authentication code is this:
secret_key = os.environ.get('secret_key')
secret_key_api = os.environ.get('secret_key_api')
access_token = os.environ.get('acess_token')
access_token_api = os.environ.get('access_token_api')
auth = tweepy.OAuthHandler(secret_key, secret_key_api)
auth.set_access_token(access_token, access_token_api)
api = tweepy.API(auth)
In case, it is caused by requirements.txt, here are the things I included:
Django==4.0.5
django-environ==0.9.0
asgiref==3.4.1
pytz==2022.5
schedule==1.1.0
tweepy==4.11.0
tzdata==2022.1
urllib3==1.26.9
gunicorn==19.0.0
whitenoise==6.0.0

I can not run a server on Django

I have a problem: after the python manage.py runserver command I receive the following error which I can not solve:
Unhandled exception in thread started by <function wrapper at 0xb6712e64>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 107, in inner_run
autoreload.raise_last_exception()
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 252, in raise_last_exception
six.reraise(*_exception)
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/dist-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/usr/lib/python2.7/dist-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/redactor/admin.py", line 3, in <module>
from redactor.widgets import JQueryEditor
ImportError: cannot import name JQueryEditor
How can I solve this problem? Many where we recommend that you sudo easy_install pip the team, but it did not help.
Are you sure that the name of the widget class is correct?
I was checking django-redactor and django-redactoreditor and they don't have a class named "JQueryEditor".

Django + Djangae + Nose / Fail wsgi

I'm currently trying to setting up django-nose in my project.
I also used Djangae (https://djangae.readthedocs.org/en/latest/) for app engine compatibility.
I add 'django_nose' in my INSTALLED_APPS
I set TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
Launching "python manage.py test" is not raising any exceptions.
But when I want to launch the server with "python manage.py runserver", the server is running but when I try to call "localhost:8000" I get :
ERROR 2016-03-23 15:59:49,299 wsgi.py:263]
Traceback (most recent call last):
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/Users/briva/Desktop/dangoptest/dangoptest/wsgi.py", line 18, in <module>
application = DjangaeApplication(get_wsgi_application())
File "/Users/briva/Desktop/dangoptest/lib/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/Users/briva/Desktop/dangoptest/lib/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/briva/Desktop/dangoptest/lib/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/briva/Desktop/dangoptest/lib/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "lib/django_nose/__init__.py", line 5, in <module>
from django_nose.runner import BasicNoseRunner, NoseTestSuiteRunner
File "lib/django_nose/runner.py", line 61, in <module>
from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
ImportError: No module named simple
Thanks for answers.

ImproperlyConfigured: Django 1.5 is not supported

I'm using the python django framework for a web app on an Ubuntu Virtual Machine. I have run the app before on another virtual machine and it worked perfectly. I think everything is inatalled ok as I can runserver amd collectstatic without any issues.
However, upon pages load I'm give the traceback;
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 72, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 243, in __call__
signals.request_started.send(sender=self.__class__)
File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 58, in reset_queries
for conn in connections.all():
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 105, in all
return [self[alias] for alias in self]
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py", line 31, in <module>
raise ImproperlyConfigured("Django %d.%d is not supported." % DjangoVersion[:2])
ImproperlyConfigured: Django 1.5 is not supported.
[11/Sep/2014 08:56:51] "GET /input_parameters HTTP/1.1" 500 59
Can anybody help me? Thanks

Django and python 2.7 from ports on Mac OS X

I have Django 1.4.1 and Python 2.7 installed from ports on Mac OS X 10.7. When I try to run manage.py runserver 8000, I'm getting an error:
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10bb840d0>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name, True)
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/rankor777/PycharmProjects/PyCart/PyCartApp/models.py", line 40, in <module>
class Photo(models.Model):
File "/Users/rankor777/PycharmProjects/PyCart/PyCartApp/models.py", line 41, in Photo
title = models.Model(max_length=128)
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 289, in __init__
if args_len > len(self._meta.fields):
AttributeError: 'Model' object has no attribute '_meta'
What's this, and how to fix it?
I don't know why you think this has something to do with MacPorts. The traceback shows the error, which is in line 41 of PyCartApp/models.py: you've put models.Model(max_length=128) where I presume you meant to put models.CharField(max_length=128).

Categories