django & send_mail in docker leads to SMTPServerDisconnected - django

I setup a google email backend for django and all is working fine until i run the whole stuff in docker-compose containers.
SMTPServerDisconnected at /events/register/4/
please run connect() first
Request Method: GET
Request URL: http://192.168.99.100:80/events/register/4/
Django Version: 1.11.3
Exception Type: SMTPServerDisconnected
Exception Value:
please run connect() first
Exception Location: /usr/local/lib/python3.6/smtplib.py in send, line 359
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.6.2
Python Path:
['.',
'',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages',
'/app']
Server time: Tue, 25 Jul 2017 11:07:45 +0200
Any idea what's going wrong here? Why is it disconnecting in a container?

Just figured it out:
In the docker-compose.yml i have something like this:
env_file:
- ".env"
The content of the .env was:
key = value
This runs great on a local machine loading the .env file first.
However docker needs a more strict format:
key=value
No spaces!!
The error was that my EMAIL_* settings wasn't set correctly with spaced key/value pairs

Related

Not able to save data in Database using for loop

my proposal:
I want add network IP range with prefix in web UI and need to process using command
ipaddress.IPv4Network(subnet).hosts())
then after IP range will crate and save all range of IP into DATABASE.
I have tried deferent methods still not able to complete my requirement.
some one could help about.
below the code which I made.
def Indexping(request):
form = IpModelForm
Ipform = {'form':form}
if request.method=='POST':
subnet = IpModelForm(request.POST)
if subnet.is_valid:
data= list(ipaddress.IPv4Network(subnet).hosts())
for f in data:
#f = [x for x in subnet]
f.save()
Exception Value:
Only one '/' permitted in
Getting Below Error:
AddressValueError at /cbv/ind/
Only one '/' permitted in
Request Method: POST
Request URL: http://127.0.0.1:8000/cbv/ind/
Django Version: 4.0.2
Exception Type: AddressValueError
Exception Value:
Only one '/' permitted in
Exception Location: D:\Program Files\Python\Python39\lib\ipaddress.py, line 162, in _split_optional_netmask
Python Executable: E:\Django_Projects\Portal-env\Scripts\python.exe
Python Version: 3.9.10
Python Path:
['E:\Django_Projects\Portal-env\portal',
'D:\Program Files\Python\Python39\python39.zip',
'D:\Program Files\Python\Python39\DLLs',
'D:\Program Files\Python\Python39\lib',
'D:\Program Files\Python\Python39',
'E:\Django_Projects\Portal-env',
'E:\Django_Projects\Portal-env\lib\site-packages']
Server time: Sat, 19 Feb 2022 09:35:57 +0000

attempt to write a readonly database

Request Method: POST
Request URL: http://localhost:8000/users/
Django Version: 3.0.3
Exception Type: OperationalError
Exception Value:
**attempt to write a readonly database**
Exception Location: C:\Users\parul\anaconda\envs\MyDjangoEnv\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 396
Python Executable: C:\Users\parul\anaconda\envs\MyDjangoEnv\python.exe
Python Version: 3.8.5
Python Path:
['C:\\Users\\parul\\Desktop\\Djangoforms\\ProTwo',
'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv\\python38.zip',
'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv\\DLLs',
'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv\\lib',
'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv',
'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv\\lib\\site-packages']
Server time: Wed, 23 Dec 2020 16:14:46 +0000
Also, i checked the properties in db.sqlite3, all the permissions are checked...write permission also
can anyone help
using windows... i tried : cacls . /t /e /g everyone:f
but still facing the same issue
Make permissions for the folder that contains the Database will solve the problem.
Also, you can run it as administrator to solve problem.

Pytest not working with Django and Docker - AssertionError: local('/dev/console') is not a file

I'm running a Django application in Docker and everything works fine but when I try try to run tests it fails with quite ambiguous error.
running docker-compose run djangoapp coverage run -m pytest
result:
Creating djangoapp_run ... done ================================================= test session starts ==================================================
platform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /
collected 0 items / 1 error
======================================================== ERRORS ========================================================
____________________________________________ ERROR collecting test session _____________________________________________
usr/local/lib/python3.8/dist-packages/_pytest/runner.py:311: in from_call
result: Optional[TResult] = func()
usr/local/lib/python3.8/dist-packages/_pytest/runner.py:341: in <lambda>
call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
usr/local/lib/python3.8/dist-packages/_pytest/main.py:710: in collect
for x in self._collectfile(path):
usr/local/lib/python3.8/dist-packages/_pytest/main.py:546: in _collectfile
assert (
E AssertionError: local('/dev/console') is not a file (isdir=False, exists=True, islink=False)
=============================================== short test summary info ================================================
ERROR - AssertionError: local('/dev/console') is not a file (isdir=False, exists=True, islink=False)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================================== 1 error in 0.33s ===================================================
docker-compose:
version: '3'
services:
djangoapp:
build: .
container_name: djangoapp
ports:
- '8000:80'
- '1433:1433'
volumes:
- ./djangoapp:/var/www/html/djangoapp
environment:
- PYTHONUNBUFFERED=0
pytest traverses recursively and default working directory in docker is /. To combine these... Set working directly correctly!
...
environment:
- PYTHONUNBUFFERED=0
working_dir: /var/www/html/djangoapp
...

Mailgun 404 error with Pythonanywhere

I'm trying to use mailgun in my Django project hosted on Pythonanywhere.
In my WSGI file, I have:
os.environ['DJANGO_MAILGUN_SERVER_NAME'] = 'https://api.mailgun.net/v3/sandboxnumbersomething.mailgun.org/messages'
os.environ['DJANGO_MAILGUN_API_KEY'] ='mykey'
and my settings are:
# EMAIL
# ------------------------------------------------------------------------------
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
default='Apitrak <noreply#apitrak.com>')
EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
MAILGUN_ACCESS_KEY = env('DJANGO_MAILGUN_API_KEY')
MAILGUN_SERVER_NAME = env('DJANGO_MAILGUN_SERVER_NAME')
When my app fire an email (for example at signup), I have a 404 error:
MailgunAPIError at /accounts/email/
<Response [404]>
Request Method: POST
Request URL: https://vincentle.pythonanywhere.com/accounts/email/
Django Version: 1.8.6
Exception Type: MailgunAPIError
Exception Value:
<Response [404]>
Exception Location: /home/vincentle/.virtualenvs/apitrak/lib/python3.4/site-packages/django_mailgun.py in _send, line 154
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.4.0
Python Path:
['/var/www',
'.',
'',
'/var/www',
'/home/vincentle/.virtualenvs/apitrak/lib/python3.4',
'/home/vincentle/.virtualenvs/apitrak/lib/python3.4/plat-x86_64-linux-gnu',
'/home/vincentle/.virtualenvs/apitrak/lib/python3.4/lib-dynload',
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-x86_64-linux-gnu',
'/home/vincentle/.virtualenvs/apitrak/lib/python3.4/site-packages',
'/home/vincentle/apitrak']
Server time: Tue, 17 Nov 2015 16:02:28 +0100
I've tried a curl in the virtualenv of my WebApp:
curl -s --user 'api:key-NUMBERS' https://api.mailgun.net/v3/NUMBERS.mailgun.org/messages -F from='Excited User <excited#samples.mailgun.org>' -F to='vincent#vincentle.fr' -F subject='Hello' -F text='Testing some Mailgun awesomeness!'
And this works OK.
The setting DJANGO_MAILGUN_SERVER_NAME should be a domain name, not a url.
Try the following:
os.environ['DJANGO_MAILGUN_SERVER_NAME'] = '<sandboxnumbersomething>.mailgun.org'
From the readme:
Replace SERVER-NAME with the last part of your "API Base URL" (e.g. https://api.mailgun.net/v3/<your_server_name>), also found in your Mailgun account details.

serving static files from heroku

I have created a simple portfolio website on manojmj.herokuapp.com
I want to host the images,css etc on heroku itself and does not want to move to s3 since its only 800kb in size.
My site is running fine and displaying the images correctly on my local dev server(127.0.0.1:8000)
However, on manojmj.herokuapp.com I can see only the markup and no images.
When I click the image url I get the errror:
ValueError at /static/images/me.jpg
dictionary update sequence element #0 has length 35; 2 is required
Request Method: GET
Request URL: http://www.manojmj.com/static/images/me.jpg
Django Version: 1.4.3
Exception Type: ValueError
Exception Value:
dictionary update sequence element #0 has length 35; 2 is required
Exception Location: /app/.heroku/python/lib/python2.7/site- packages/django/core/urlresolvers.py in resolve, line 207
Python Executable: /app/.heroku/python/bin/python
Python Version: 2.7.4
Python Path:
['/app',
'/app/.heroku/python/bin',
'/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.36-py2.7.egg',
'/app/.heroku/python/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
'/app',
'/app/.heroku/python/lib/python27.zip',
'/app/.heroku/python/lib/python2.7',
'/app/.heroku/python/lib/python2.7/plat-linux2',
'/app/.heroku/python/lib/python2.7/lib-tk',
'/app/.heroku/python/lib/python2.7/lib-old',
'/app/.heroku/python/lib/python2.7/lib-dynload',
'/app/.heroku/python/lib/python2.7/site-packages',
'/app/.heroku/python/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Server time: Fri, 21 Jun 2013 09:37:01 -0500
my urls.py
url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root: settings.STATIC_ROOT'}),
url(r'^static/css/(?P<path>.*)$','django.views.static.serve',{'document_root: settings.STATIC_ROOT'}),
url(r'^static/images/(?P<path>.*)$','django.views.static.serve','document_root: settings.STATIC_ROOT'),
url(r'^static/js/(?P<path>.*)$','django.views.static.serve',{'document_root: settings.STATIC_ROOT'}),
url(r'^hello/', 'manojmjapp.views.hello'),
url(r'^$', 'manojmjapp.views.home'),
try to change this line :
url(r'^static/images/(?P<path>.*)$','django.views.static.serve','document_root: settings.STATIC_ROOT'),
for this:
url(r'^static/images/(?P<path>.*)$','django.views.static.serve',{'document_root': 'settings.STATIC_ROOT'}),