I am unable to resolve this error. I am running django. It works properly on my local, but I have deployed the code to aws elasticbeanstalk where it throws the below error.
Also my smtp configuration is something like this.
I have also tried to ALLOW low secure apps in Google settings.
But nothing seems to work.
# SMTP configuration
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'email#gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
Environment:
Request Method: POST
Request URL: http://odm-masala-app-env.eba-ijhfppue.us-west-2.elasticbeanstalk.com/accounts/register/
Django Version: 3.1
Python Version: 3.7.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'category',
'accounts',
'store',
'carts',
'orders',
'admin_honeypot',
'storages']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_session_timeout.middleware.SessionTimeoutMiddleware']
Traceback (most recent call last):
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/app/current/accounts/views.py", line 53, in register
send_email.send()
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/django/core/mail/message.py", line 284, in send
return self.get_connection(fail_silently).send_messages([self])
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
new_conn_created = self.open()
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 69, in open
self.connection.login(self.username, self.password)
File "/usr/lib64/python3.7/smtplib.py", line 730, in login
raise last_exception
File "/usr/lib64/python3.7/smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "/usr/lib64/python3.7/smtplib.py", line 642, in auth
raise SMTPAuthenticationError(code, resp)
Exception Type: SMTPAuthenticationError at /accounts/register/
Exception Value: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt\n5.7.14 JzmJlDR_KXwRjsGoeGbUwfJiFaseGdN7r4Tr5kVIBAWkZ_KxJtmoZ21tvxssaWR96lYr1\n5.7.14 1McFMOBeAoLgjKAhaZSf7Z0H7mCYUPyXbKlQ-CmDohYCNFK3GmWZG47EBOB2uOnH>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 63sm12202837pfz.119 - gsmtp')
This is because gmail uses captcha verification, please try disabling it from below link.
https://accounts.google.com/DisplayUnlockCaptcha
Related
I am getting the error Manager isn't accessible via Contact instances
StackTrace
Environment:
Request Method: POST
Request URL: http://localhost:8000/upload/
Django Version: 3.1.7
Python Version: 3.9.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'contactapp']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "/Users/Me/.local/share/virtualenvs/test_code-Xw7ix4y5/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/Me/.local/share/virtualenvs/test_code-Xw7ix4y5/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/Me/Data/Clients/BanzaiPythonTest/test_code/contactapp/views.py", line 39, in upload_file
print(result.get())
File "/Users/Me/.local/share/virtualenvs/test_code-Xw7ix4y5/lib/python3.9/site-packages/celery/result.py", line 223, in get
return self.backend.wait_for_pending(
File "/Users/Me/.local/share/virtualenvs/test_code-Xw7ix4y5/lib/python3.9/site-packages/celery/backends/asynchronous.py", line 201, in wait_for_pending
return result.maybe_throw(callback=callback, propagate=propagate)
File "/Users/Me/.local/share/virtualenvs/test_code-Xw7ix4y5/lib/python3.9/site-packages/celery/result.py", line 335, in maybe_throw
self.throw(value, self._to_remote_traceback(tb))
File "/Users/Me/.local/share/virtualenvs/test_code-Xw7ix4y5/lib/python3.9/site-packages/celery/result.py", line 328, in throw
self.on_ready.throw(*args, **kwargs)
File "/Users/Me/.local/share/virtualenvs/test_code-Xw7ix4y5/lib/python3.9/site-packages/vine/promises.py", line 234, in throw
reraise(type(exc), exc, tb)
File "/Users/Me/.local/share/virtualenvs/test_code-Xw7ix4y5/lib/python3.9/site-packages/vine/utils.py", line 30, in reraise
raise value
Exception Type: AttributeError at /upload/
Exception Value: Manager isn't accessible via Contact instances
I am making a utility function and below is my code:
class Contact(models.Model):
name = models.CharField(max_length=100)
phone = models.CharField(max_length=20, null=True)
email = models.CharField(max_length=256,
null=True) # Ref: https://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
created_at = models.DateTimeField(auto_now_add=True)
def __repr__(self):
return self.name
def get_records_by_duration(self, duration=3):
minutes_ago = now() + datetime.timedelta(minutes=-duration)
contact_object = Contact.objects.filter(
(Q(email__in=['adn#mae.com', 'adnan#gmail.com']) | Q(phone__in=[])),
Q(created_at__gte=minutes_ago))
total = contact_object.count()
print('Total = {}'.format(total))
In my view I am doing the following:
contact_object = Contact()
result = contact_object.get_records_by_duration()
contact_object is an instance of Contact class. In django the table-level operations has to be accessed from the class not the instance of the class. So,
Contact.get_records_by_duration() should work I think.
Also see here:
Manager isn't accessible via model instances
I am creating REST api, with Django Rest Framework, and first of all I have to give users the way to register. I saw django-rest-registration as easy way to make this, but when I did everything as is said in Quickstart, my terminal throws those errors:
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
?: (rest_registration.E001) RESET_PASSWORD_VERIFICATION_URL is not set
?: (rest_registration.E004) VERIFICATION_FROM_EMAIL is not set
System check identified 2 issues (0 silenced).
Here's my code:
settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'rest_registration',
'app',
]
REST_REGISTRATION = {
'REGISTER_VERIFICATION_ENABLED': False,
'REGISTER_EMAIL_VERIFICATION_ENABLED': False,
'RESET_PASSWORD_VERIFICATION_ENABLED': False,
}
urlpatterns:
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('app.urls')),
path('accounts/', include('rest_registration.api.urls')),
]
But, when I tried to change REST_REGISTRATION to this:
REST_REGISTRATION = {
'REGISTER_VERIFICATION_URL': 'https://frontend-host/verify-user/',
'RESET_PASSWORD_VERIFICATION_URL': 'https://frontend-host/reset-password/',
'REGISTER_EMAIL_VERIFICATION_URL': 'https://frontend-host/verify-email/',
'VERIFICATION_FROM_EMAIL': 'no-reply#example.com',
}
and I submitted the request, I saw another error:
ConnectionRefusedError at /accounts/register/
+ Traceback:
Environment:
Request Method: POST
Request URL: http://localhost:8000/accounts/register/
Django Version: 2.2.3
Python Version: 3.7.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'rest_registration',
'app']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/views/generic/base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_framework/views.py" in dispatch
495. response = self.handle_exception(exc)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_framework/views.py" in handle_exception
455. self.raise_uncaught_exception(exc)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_framework/views.py" in dispatch
492. response = handler(request, *args, **kwargs)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_framework/decorators.py" in handler
55. return func(*args, **kwargs)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_registration/api/views/register.py" in register
96. send_verification_notification(user, signer, template_config)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_registration/notifications/email.py" in send_verification_notification
24. send_notification(notification)
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/rest_registration/notifications/email.py" in send_notification
209. notification.send()
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/mail/message.py" in send
291. return self.get_connection(fail_silently).send_messages([self])
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py" in send_messages
103. new_conn_created = self.open()
File "/home/fullnamedebian/.local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py" in open
63. self.connection = self.connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python3.7/smtplib.py" in __init__
251. (code, msg) = self.connect(host, port)
File "/usr/lib/python3.7/smtplib.py" in connect
336. self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.7/smtplib.py" in _get_socket
307. self.source_address)
File "/usr/lib/python3.7/socket.py" in create_connection
727. raise err
File "/usr/lib/python3.7/socket.py" in create_connection
716. sock.connect(sa)
Exception Type: ConnectionRefusedError at /accounts/register/
Exception Value: [Errno 111] Connection refused
I added email settings:
# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 8000
And now when I submit post I just see this in terminal: [22/Sep/2019 14:44:54] "POST /accounts/register/ HTTP/1.1" 400 13646 (Its drawn with red font, if it matters). And webpage is loading infinitley.
I have this error for 2 days now I triyed everything in the other topics nothings works for me. The code of the app was written in linux, but i got the folder and connected it to my project as an app, in this project there is 3 apps that are connecting good to the database, only this one gives an error unable to open data base. I'm using Windows on Localhost, a friend triyed on windows and it's working for him, only for me not working.
Note : When I go to localhost:8000/admin I can see the model created on the database.
PLEASE HELP!
Django Version: 2.2.3
I have tryied to give permissions of the folder on it's proprieties to read and write, tryied to change path of DIR, I switched from sqlite3 to postgres, made full path in database and not full one, triyed all the recommandations on topics but still shows the error
Settings. py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'devee',
'USER': 'postgres',
'PASSWORD': 'thepasswordichoosed',
'HOST': 'localhost',
'PORT': '5432',
}
}
Environment:
Request Method: POST
Request URL: http://localhost:8000/result
Django Version: 2.2.3
Python Version: 3.7.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dashboard',
'account',
'analyse']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "C:\Users\I500913\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Users\I500913\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\handlers\base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "C:\Users\I500913\AppData\Local\Continuum\anaconda3\lib\site-packages\django\core\handlers\base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\I500913\AppData\Local\Continuum\anaconda3\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "C:\Users\I500913\Desktop\Projets\final\analyse\views.py" in analyse_result
22. seo_score, report = scrapper(website)
File "C:\Users\I500913\Desktop\Projets\final\analyse\seo_scrapper.py" in scrapper
411. sbl = SafeBrowsingList(api_key)
File "C:\Users\I500913\AppData\Local\Continuum\anaconda3\lib\site-packages\gglsbl\client.py" in __init__
35. self.storage = SqliteStorage(db_path, timeout=timeout)
File "C:\Users\I500913\AppData\Local\Continuum\anaconda3\lib\site-packages\gglsbl\storage.py" in __init__
73. self.db = sqlite3.connect(db_path, timeout)
Exception Type: OperationalError at /result
Exception Value: unable to open database file
I have a Django App that accept images through REST-api. I tested the api using POSTMAN locally, it's working perfect with image uploads. Later I deployed it on OpenShift V3 and when I tried the same for uploading process using POSTMAN , it's saying
Server Traceback
Environment:
Request Method: POST
Request URL: http://django-psql-persistent-sampledjangoex.44fs.preview.openshiftapps.com/myapp/sample/
Django Version: 1.9
Python Version: 3.5.1
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'welcome',
'rest_framework')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware')
Traceback:
File "/opt/app-root/src/.local/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
174. response = self.process_exception_by_middleware(e, request)
File "/opt/app-root/src/.local/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
172. response = response.render()
File "/opt/app-root/src/.local/lib/python3.5/site-packages/django/template/response.py" in render
160. self.content = self.rendered_content
File "/opt/app-root/src/.local/lib/python3.5/site-packages/rest_framework/response.py" in rendered_content
71. ret = renderer.render(self.data, media_type, context)
File "/opt/app-root/src/.local/lib/python3.5/site-packages/rest_framework/renderers.py" in render
104. separators=separators
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/json/__init__.py" in dumps
237. **kw).encode(obj)
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/json/encoder.py" in encode
199. chunks = self.iterencode(o, _one_shot=True)
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/json/encoder.py" in iterencode
257. return _iterencode(o, 0)
File "/opt/app-root/src/.local/lib/python3.5/site-packages/rest_framework/utils/encoders.py" in default
64. return super(JSONEncoder, self).default(obj)
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/json/encoder.py" in default
180. raise TypeError(repr(o) + " is not JSON serializable")
Exception Type: TypeError at /myapp/sample/
Exception Value: b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\x06\x04\x05\x06\x05\x04\x06\x06\x05\x06\x07\x07\x06\x08\n' is not JSON serializable
Here is the source Code of the Program
Note: I can do uploading process through DRF-Browsable api
First of all I would say thanks to #Raz. Actually the tool POSTMAN caused the issue. I tested the OpenShift-v3 api using Python's Request library. It's worked :)
Code I used;
import requests
from requests.auth import HTTPBasicAuth
url = 'http://django-psql-persistent-sampledjangoex.44fs.preview.openshiftapps.com/myapp/sample/'
filess = {'image': open('sampleImage.png', 'rb')}
r = requests.post(url,data={'name': 'value1', 'number': 12573474},auth=HTTPBasicAuth('admin', 'admin'),files=filess)
i'm trying to get a contact form on a personal site to work.
i'm using the smtp outlook.
Right now it gives me the following error:
Traceback:
Environment:
Request Method: POST
Request URL: *******
Django Version: 1.8.1
Python Version: 3.4.0
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/Nmaster88/Ngranja/Ngranja/Ngranja/views.py" in sendmail
23. send_mail(request.POST['contactSubject'],"From: "+request.POST['contactEmail']+'\n\n'+request.POST['contactMessage'],request.POST['contactEmail'],['nunomaster_#hotmail.com'],)
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/mail/__init__.py" in send_mail
62. return mail.send()
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/mail/message.py" in send
303. return self.get_connection(fail_silently).send_messages([self])
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in send_messages
100. new_conn_created = self.open()
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in open
58. self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python3.4/smtplib.py" in __init__
242. (code, msg) = self.connect(host, port)
File "/usr/lib/python3.4/smtplib.py" in connect
321. self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.4/smtplib.py" in _get_socket
292. self.source_address)
File "/usr/lib/python3.4/socket.py" in create_connection
509. raise err
File "/usr/lib/python3.4/socket.py" in create_connection
500. sock.connect(sa)
Exception Type: ConnectionRefusedError at /
Exception Value: [Errno 111] Connection refused
my settings:
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = 'myemail#hotmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 25
EMAIL_USE_TLS = True
view file:
from django.http import HttpResponseRedirect
from django.core.mail import send_mail
from django.shortcuts import render
def sendmail(request):
errors=[]
if request.method == 'POST':
if not request.POST.get('contactName',''):
errors.append('Coloca um nome.')
if not request.POST.get('contactEmail',''):
errors.append('Coloca um email.')
if not request.POST.get('contactSubject',''):
errors.append('Coloca um assunto.')
if not request.POST.get('contactMessage',''):
errors.append('Coloca um assunto.')
if not errors:
subject=request.POST['contactSubject']
email=request.POST['contactEmail']
message=request.POST['contactMessage']
send_mail(subject,"From: "+email+'\n\n'+message,email,['myemail#hotmail.com'], fail_silently=False)
return HttpResponseRedirect('/thankyou/')
return render(request, "mypage.html", {'errors': errors})
Does anyone has a clue on what is wrong?
If necessary i can give more info on the app
[EDIT]
I'm hosting the page at pythonanywhere.com, does the error have something to do with the server?
[EDIT] SOLVED
Pythonanywhere for free users only works for Gmail, and i had to give it permission for less secure apps! Now it works fine.
Try using use_ssl=True in your SMTP settings and changing the port to 465.
You can directly refer to Django SMTP options for list of all the settings you can tweak.
Also please mention which Django version you are using for building your app?