My django project sends email verification correctly till its using uWSGI, when i run it with uWSGI i am unable to send email, it sometimes sends as well sometimes it doesnt.
it doesnt show any error in console
Nginx config:
upstream django {
server unix://ucurs/ucurs.sock; # for a file socket
}
# configuration of the server
server {
# the port your site will be served on
listen 7000;
# the domain name it will serve for
server_name 127.0.0.1; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location /log {
access_log off;
error_log off;
uwsgi_pass django;
include /ucurs/uwsgi_params;
}
# Django media
location /media {
alias /ucurs/media; # your Django project's media files - amend as required
}
location /static {
alias /ucurs/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /ucurs/uwsgi_params; # the uwsgi_params file you installed
}
}
Django library used for sending email : https://pypi.org/project/django-email-verification/
Django email config
EMAIL_FROM_ADDRESS = 'noreply#ucurs.com'
EMAIL_MAIL_SUBJECT = 'Confirm your email'
EMAIL_MAIL_HTML = 'mail_body.html'
EMAIL_MAIL_PLAIN = 'mail_body.txt'
EMAIL_TOKEN_LIFE = 60 * 60
EMAIL_PAGE_TEMPLATE = 'confirm_template.html'
EMAIL_PAGE_DOMAIN = 'https://backend.ucurs.com/'
EMAIL_HOST = 'smtp.kryptohive.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'noreply#ucurs.com'
EMAIL_HOST_PASSWORD = '******'
EMAIL_USE_TLS = True
uswgi.ini :
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = .
# Django's wsgi file
module = ucurs_backend.wsgi
logto = report/uswgi_logs
# the virtualenv (full path)
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = ucurs.sock
# ... with appropriate permissions - may be needed
chown-socket = www-data:www-data
chmod-socket = 777
uid = www-data
gid = www-data
# clear environment on exit
vacuum = true
byte_size = 65535
uswgi_params :
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
EDIT 2
Tcpdump from django server shows no traffic for mail, so issue is in uswgi
09:20:35.298648 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [S], seq 1191300539, win 64240, options [mss 1460,sackOK,TS val 912819442 ecr 0,nop,wscale 7], length 0
09:20:35.298775 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [S.], seq 1210865976, ack 1191300540, win 65160, options [mss 1460,sackOK,TS val 3498762181 ecr 912819442,nop,wscale 7], length 0
09:20:35.298815 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [.], ack 1, win 502, options [nop,nop,TS val 912819442 ecr 3498762181], length 0
09:20:35.298895 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 1:9, ack 1, win 502, options [nop,nop,TS val 912819442 ecr 3498762181], length 8
09:20:35.298911 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [.], ack 9, win 509, options [nop,nop,TS val 3498762181 ecr 912819442], length 0
09:20:35.301343 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 1:2, ack 9, win 509, options [nop,nop,TS val 3498762183 ecr 912819442], length 1
09:20:35.301356 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [.], ack 2, win 502, options [nop,nop,TS val 912819444 ecr 3498762183], length 0
09:20:35.303706 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 2:15, ack 50, win 509, options [nop,nop,TS val 3498762186 ecr 912819444], length 13
09:20:35.303795 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 50:91, ack 15, win 502, options [nop,nop,TS val 912819447 ecr 3498762186], length 41
09:20:35.306641 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 15:341, ack 91, win 509, options [nop,nop,TS val 3498762189 ecr 912819447], length 326
09:20:35.307576 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 91:116, ack 341, win 501, options [nop,nop,TS val 912819451 ecr 3498762189], length 25
09:20:35.308579 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 341:374, ack 116, win 509, options [nop,nop,TS val 3498762191 ecr 912819451], length 33
09:20:35.308966 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 116:222, ack 374, win 501, options [nop,nop,TS val 912819452 ecr 3498762191], length 106
09:20:35.315080 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 374:421, ack 222, win 509, options [nop,nop,TS val 3498762197 ecr 912819452], length 47
09:20:35.319524 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 222:336, ack 421, win 501, options [nop,nop,TS val 912819463 ecr 3498762197], length 114
09:20:35.322154 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 421:468, ack 336, win 509, options [nop,nop,TS val 3498762204 ecr 912819463], length 47
09:20:35.362825 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [.], ack 468, win 501, options [nop,nop,TS val 912819506 ecr 3498762204], length 0
09:20:35.605078 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 336:873, ack 468, win 501, options [nop,nop,TS val 912819748 ecr 3498762204], length 537
09:20:35.614358 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 468:531, ack 873, win 505, options [nop,nop,TS val 3498762496 ecr 912819748], length 63
09:20:35.614387 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [.], ack 531, win 501, options [nop,nop,TS val 912819757 ecr 3498762496], length 0
09:20:35.616039 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 873:1076, ack 531, win 501, options [nop,nop,TS val 912819759 ecr 3498762496], length 203
09:20:35.619838 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 531:594, ack 1076, win 504, options [nop,nop,TS val 3498762502 ecr 912819759], length 63
09:20:35.620982 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 1076:1621, ack 594, win 501, options [nop,nop,TS val 912819764 ecr 3498762502], length 545
09:20:35.622083 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [P.], seq 594:614, ack 1621, win 501, options [nop,nop,TS val 3498762504 ecr 912819764], length 20
09:20:35.629989 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [P.], seq 1621:1626, ack 614, win 501, options [nop,nop,TS val 912819773 ecr 3498762504], length 5
09:20:35.633474 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [F.], seq 1626, ack 614, win 501, options [nop,nop,TS val 912819776 ecr 3498762504], length 0
09:20:35.633998 IP psql_db.prod_default.postgresql > ce2fc225de38.56560: Flags [F.], seq 614, ack 1627, win 501, options [nop,nop,TS val 3498762516 ecr 912819773], length 0
09:20:35.634021 IP ce2fc225de38.56560 > psql_db.prod_default.postgresql: Flags [.], ack 615, win 501, options [nop,nop,TS val 912819777 ecr 3498762516], length 0
09:20:38.494868 IP6 fe80::a8a0:99ff:fe25:6d1f > ip6-allrouters: ICMP6, router solicitation, length 16
09:20:38.496166 IP ce2fc225de38.35901 > one.one.one.one.domain: 58550+ PTR? f.1.d.6.5.2.e.f.f.f.9.9.0.a.8.a.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa. (90)
09:20:38.497435 IP one.one.one.one.domain > ce2fc225de38.35901: 58550 NXDomain 0/0/0 (90)
09:20:38.497661 IP ce2fc225de38.48162 > dns.google.domain: 58550+ PTR? f.1.d.6.5.2.e.f.f.f.9.9.0.a.8.a.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa. (90)
09:20:38.499486 IP dns.google.domain > ce2fc225de38.48162: 58550 NXDomain 0/1/0 (154)
09:20:38.500424 IP ce2fc225de38.37933 > one.one.one.one.domain: 58885+ PTR? 1.1.1.1.in-addr.arpa. (38)
09:20:38.501094 IP one.one.one.one.domain > ce2fc225de38.37933: 58885 1/0/0 PTR one.one.one.one. (67)
09:20:38.502256 IP ce2fc225de38.39070 > one.one.one.one.domain: 65529+ PTR? 8.8.8.8.in-addr.arpa. (38)
09:20:38.502846 IP one.one.one.one.domain > ce2fc225de38.39070: 65529 1/0/0 PTR dns.google. (62)
09:21:31.742925 IP6 fe80::a8a0:99ff:fe25:6d1f > ip6-allrouters: ICMP6, router solicitation, length 16
09:23:12.094915 IP6 fe80::a8a0:99ff:fe25:6d1f > ip6-allrouters: ICMP6, router solicitation, length 16
09:26:32.798927 IP6 fe80::a8a0:99ff:fe25:6d1f > ip6-allrouters: ICMP6, router solicitation, length 16
EDIT 3
I have finally confiremd issue is in uswgi configurations, as i tried proxy pass django development server and it works fine
proxy_pass http://ucurs_backend:8000;
# uwsgi_pass django;
# include /ucurs/uwsgi_params; # the uwsgi_params file you installed
Observation
closing uwsgi server sends all mails
I try to start a SNMP Agent with pysnmp.
for IPv4 and IPv6 bind, it works pretty fine with localhost ('127.0.0.1' and '::1')
but when I try to use other IPv6 IP which I fetched from interface, it failed due to
[vagrant#test SOURCES]$ sudo python snmp_agent.py enp0s8
Traceback (most recent call last):
File "snmp_agent.py", line 172, in <module>
master_agent_startup(ifname=sys.argv[1])
File "snmp_agent.py", line 101, in master_agent_startup
(get_ipv6_address(interface_name), SNMP_AGENT_PORT))
File "/usr/lib/python2.7/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 50, in openServerMode
raise error.CarrierError('bind() for %s failed: %s' % (iface, sys.exc_info()[1],))
pysnmp.carrier.error.CarrierError: bind() for ('fe80::a00:27ff:fe9e:9c16', 8001) failed: [Errno 22] Invalid argument
This is the output from the interface 'enp0s8':
[vagrant#test SOURCES]$ ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.20.26 netmask 255.255.255.0 broadcast 172.20.20.255
inet6 fe80::a00:27ff:fe9e:9c16 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:9e:9c:16 txqueuelen 1000 (Ethernet)
RX packets 874053 bytes 115842841 (110.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 862314 bytes 114652475 (109.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
This is the code piece I used for IPv6 bind:
def get_ipv6_address(ifname):
return netifaces.ifaddresses(ifname)[netifaces.AF_INET6][0]['addr'].split('%')[0]
config.addSocketTransport(snmpEngine, udp.domainName,
udp.UdpTransport().openServerMode(
(get_ipv4_address(interface_name), SNMP_AGENT_PORT))
)
config.addSocketTransport(snmpEngine, udp6.domainName,
udp6.Udp6SocketTransport().openServerMode(
(get_ipv6_address(interface_name), SNMP_AGENT_PORT))
)
From pysnmp sample, it seems the parameter inside "openServerMode()" is just a tuple of IP and port.
And from output error I suppose there is no error for given IP and port.
so why it failed due to Invalid argument?
Could you #Ilya Etingof or some other pysnmp expert help me with it?
Thanks.
UPDATE: I try to bind it with given suggestion, but is still doesn't work.
the bind command was run from a new installed CentOS. but it still failed:
[root#test ~]# ifconfig
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.20.4 netmask 255.255.255.0 broadcast 10.10.20.255
inet6 fe80::f816:3eff:fee1:5475 prefixlen 64 scopeid 0x20<link>
ether fa:16:3e:e1:54:75 txqueuelen 1000 (Ethernet)
RX packets 12242 bytes 962552 (939.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12196 bytes 957826 (935.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root#test ~]# python
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, 0)
>>> addr_and_port = ('fe80::f816:3eff:fedb:ba4f', 8001)
>>> s.bind(addr_and_port)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 22] Invalid argument
>>>
[1]+ Stopped python
[root#test ~]# netstat -anp | grep 8001
[root#test ~]#
One more update:
I suppose the bind is failed due to my environment has some issue with IPv6 configuration. As I'm only able to get one IPv4 address by using "socket.getaddrinfo()" method.
Br,
-Dapeng Jiao
You could get this error if attempted to bind the same socket more than once. But I can't see that is the case in your code.
That .openServerMode() method does no magic -- it just calls .bind() on socket object. For inspiration, does this work in at your Python prompt?
from pysnmp.carrier.asyncore.dgram import udp6
addr_and_port = ('fe80::a00:27ff:fe9e:9c16', 8001)
udp6.Udp6SocketTransport().openServerMode(addr_and_port)
or even:
import socket
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, 0)
addr_and_port = ('fe80::a00:27ff:fe9e:9c16', 8001)
s.bind(addr_and_port)
My hope is that tests like these may help you figuring out the problem...
When you use an IPv6 link-local address, you must always use the scope along with it. The link-local address is not valid without its scope, thus you will receive an Invalid argument error.
For example, instead of using fe80::a00:27ff:fe9e:9c16 you must use fe80::a00:27ff:fe9e:9c16%enp0s8.
I use elasticsearch a lot and I needed a way to see the request to elasticsearch server.
So I found this bash script:
sudo tcpdump -A -nn -s 0 'tcp dst port 9200 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -i lo
Works well, the problem is it outputs a lot of junk:
11:40:49.690863 IP 127.0.0.1.50270 > 127.0.0.1.9200: Flags [P.], seq 2594084191:2594084256, ack 2674569216, win 342, options [nop,nop,TS val 910075 ecr 910075], length 65
E..uw.#.#............^#...._.j.....V.i.....
..HEAD / HTTP/1.1
Host: localhost:9200
Connection: keep-alive
11:40:49.707181 IP 127.0.0.1.50271 > 127.0.0.1.9200: Flags [P.], seq 3009491178:3009491248, ack 3451175088, win 342, options [nop,nop,TS val 910080 ecr 910079], length 70
E..z..#.#.jc........._#..a0........V.n.....
..GET /_nodes HTTP/1.1
Host: localhost:9200
Connection: keep-alive
11:40:52.215800 IP 127.0.0.1.50272 > 127.0.0.1.9200: Flags [P.], seq 148869443:148869508, ack 2833610757, win 342, options [nop,nop,TS val 910707 ecr 910707], length 65
E..ut3#.#..M.........`#....C..x....V.i.....
.sHEAD / HTTP/1.1
Host: localhost:9200
Connection: keep-alive
I just want to keep the JSON.
So I though about going by elimination.
I added this regex:
sudo tcpdump -A -nn -s 0 'tcp dst port 9200 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -i lo | grep -v "[0-9]{2}[:][0-9]{2}[:][0-9]{2}\.[0-9]*[ ][I][P][ ][0-9]{1,3}\.[0 -9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]*[ ][\>].*"
Here is the regex in action: https://regex101.com/r/aS6kS2/1
Anyways, what I am trying to accomplish here is to remove:
11:40:49.707181 IP 127.0.0.1.50271 > 127.0.0.1.9200: Flags [P.], seq 3009491178:3009491248, ack 3451175088, win 342, options [nop,nop,TS val 910080 ecr 910079], length 70
E..z..#.#.jc........._#..a0........V.n.....
..GET /_nodes HTTP/1.1
Host: localhost:9200
Connection: keep-alive
So that only the body/JSON is kept.
I was trying to go line by line but for now it's not even removing the first one that was the target of my regex.
This will do what you've told us about so far (remove the middle chunk of text from the sequence of 3 chunks of text):
$ awk -v RS= -v ORS='\n\n' 'NR!=2' file
11:40:49.690863 IP 127.0.0.1.50270 > 127.0.0.1.9200: Flags [P.], seq 2594084191:2594084256, ack 2674569216, win 342, options [nop,nop,TS val 910075 ecr 910075], length 65
E..uw.#.#............^#...._.j.....V.i.....
..HEAD / HTTP/1.1
Host: localhost:9200
Connection: keep-alive
11:40:52.215800 IP 127.0.0.1.50272 > 127.0.0.1.9200: Flags [P.], seq 148869443:148869508, ack 2833610757, win 342, options [nop,nop,TS val 910707 ecr 910707], length 65
E..ut3#.#..M.........`#....C..x....V.i.....
.sHEAD / HTTP/1.1
Host: localhost:9200
Connection: keep-alive
If that's not what you want then edit your question to clarify as I suggested in my comment.