django-paypal signal update - django

I've been picking my way though django-paypal documentation and have got a signal connecting when I send a IPN from the sandbox simulator.
I can do:
UserProfile.objects.update(has_paid=True)
I can also do:
UserProfile.objects.update(middle_name=sender.custom) # sender.custom set to "Lyndon" on IPN
and everyone gets a year free. Not what I want...
What I'd like to do is
up = UserProfile.objects.get(user=ipn_obj.custom)
up.has_paid = False
up.save()
but on such occasions I get a server error (500) message on the Instant Payment Notification (IPN)
simulator.
IPN delivery failed. HTTP error code 500: Internal Server Error
I still get a Paypal IPN in my database and it will show up not flagged and with a payment status of "Completed". However, the signal is not connecting.
I'm just not getting something (or multiple things!) here. Any pointers much appreciated.
T

Try to use that,
UserProfile.objects.filter(user=ipn_obj.custom).update(has_paid=False)
For that kind of bugs, which you can not understand what is the problem use ipdb:
you should install ipdb,
$ pip install ipdb
and to run go to your code which doesn't work and add,
import ipdb; ipdb.set_trace()
when you run on your local (I mean with runserver) and make request to make that code pieces run, you will see the trace after the above line.
Note that to go next use "n" and to continue use "c" on ipdb.

It would help if I paid attention...
up = UserProfile.objects.get(user.username=ipn_obj.custom)
user.username...

Related

Django post-office setup

Perhaps it is just because I've never set up an e-mail system on Django before, or maybe I'm missing it... but does anyone have any insight on how to properly configure django post-office for sending queued e-mails?
I've got a mailing list of 1500 + people, and am hosting my app on heroku - using the standard email system doesn't work because I need to send customized emails to each user, and to connect to the server one by one leads to a timeout.
I've installed django-post_office via pip install, installed the app in settings.py, I've even been able to get an email to send by going:
mail.send(['recipient'],'sender',subject='test',message='hi there',priority='now')
However, if I try to schedule for 30 seconds from now let's say:
nowtime = datetime.datetime.now()
sendtime = nowtime + datetime.timedelta(seconds=30)
and then
mail.send(['recipient'],'sender',subject='test',message='hi there',scheduled_time=sendtime)
Nothing happens... time passes, and the e-mail is still listed as queued, and I don't receive any emails.
I have a feeling it's because I need to ALSO have Celery / RQ / Cron set up??? But the documentation seems to suggest that it should work out of the box. What am I missing?
Thanks folks
Actually, you can find this in the documentation (at the time I'm writing this comment):
Usage
If you use post_office’s EmailBackend, it will automatically queue emails sent using django’s send_mail in the database.
To actually send them out, run python manage.py send_queued_mail. You can schedule this to run regularly via cron:
* * * * * (/usr/bin/python manage.py send_queued_mail >> send_mail.log 2>&1)

Learning the Twisted framework and having trouble with the finger server

I am learning the Twisted framework for a project I am working on by using the Twisted Documentation Finger tutorial (http://twistedmatrix.com/documents/current/core/howto/tutorial/intro.html) and I'm having trouble getting my program to work.
Here's the code for the server, it should return "No Such User" when I telnet localhost 12345, but it just stays there, nothing happening.
from twisted.internet import protocol, reactor
from twisted.protocols import basic
class FingerProtocol(basic.LineReceiver):
def lineReceived(self, user):
self.transport.write("No such user\r\n")
self.transport.loseConnection()
class FingerFactory(protocol.ServerFactory):
protocol = FingerProtocol
reactor.listenTCP(12345, FingerFactory())
reactor.run()
I have run the server via python twisted-finger.py and sudo python twisted-finger.py, but neither worked.
Does anyone see why this doesn't return the message it is supposed to?
You have to send a finger request to the server before it responds.
According to the finger rfc:
Send a single "command line", ending with <CRLF>.
The command line:
Systems may differ in their interpretations of this line. However,
the basic scheme is straightforward: if the line is null (i.e. just
a <CRLF> is sent) then the server should return a "default" report
which lists all people using the system at that moment. If on the
other hand a user name is specified (e.g. FOO<CRLF>) then the
response should concern only that particular user, whether logged in
or not.
Try typing a word into telnet and hitting enter.

Flask-Mail not sending emails, no error is being reported

All, I'm trying to setup flask-mail to send notifications to my email when a user registers.
I'm getting no error messages from the script used to send the email, but nothing is actually being sent, or at least, nothing is being received.
Is there a log file which can show if an email was sent, rejected, or maybe if there was even a problem logging onto the server? How does on track this problem?
Any ideas here?
Flask-Email use smtplib which can set debug level: https://github.com/mattupstate/flask-mail/blob/master/flask_mail.py#L139. You can set it with MAIL_DEBUG = True or DEBUG = True. Also check that MAIL_SUPPRESS_SEND = False and TESTING = False.
With debug I can see in stdout mail progress: success, fail, recipients and etc.
See details: http://pythonhosted.org/Flask-Mail/#configuring-flask-mail.
tbicr has the most likely fix, check MAIL_SUPPRESS_SEND first.
What ended up burning me (being new to flask) is that when you instantiate your Mail() object, be sure it's after you've set your app.config values. The Mail() object doesn't go back and look at these values after the fact, so they will default to bad values. What's frustrating is that you won't see any errors when you try to send messages with the default/bad values. At least not as of my posting.
I know this post is from a while ago, but I just ran into the same issue. Like #tbicr mentioned make sure that app.testing is set to False. As it states in the Flask-Maildocs here:
"If the setting TESTING is set to True, emails will be suppressed. Calling send() on your messages will not result in any messages being actually sent."
This was exactly my problem. I implemented Google reCAPTCHA into one of my forms and the app.testing was set to True so I did not have to hit the reCAPTCHA box every time. By removing the app.testing or by setting it to False, the emails were able to be sent.

Django - sending 600 emails with celery -- some are skipped?

I have a Django project that needs to send out around 600 emails. I have Celery set up and it works, for the most part. I have the Django project set up to use my Google Apps (Business version -- ie: paid for) email account as the sending account. For testing purposes, I have every email sent to me -- not to the client.
The issue I am having is that Celery seems to randomly skip people in the list. When I start the process of sending all 600 emails, Celery works away, sending emails (I can see them show up in my inbox) but I only receive a total of about 420 emails. When Celery finishes, there are still 180 or so people that need the email. If I click "send emails" again with ONLY the remaining 180 people, it will finish the job and, at the end of two attempts, will have sent emails to all 600 people.
Why would Celery be skipping people?
Yes, you will get those gmail errors and it's not particularly predictable.
You could just use django-mailer instead -- I do, and deal with those gmail connection errors by letting django-mailer automatically retry the failed sending attempts until they succeed.
Check out this SO question for more folks suggesting you just use django-mailer vs celery for mail.
Advice on Python/Django and message queues

django-notifications not sending any email

I'm trying to use django-notification and I can't get it to send any emails. The notifications appears in the Notices, but when I do python manage.py emit_notices this is what I get:
acquiring lock...
acquired.
(0.001) SELECT `notification_noticequeuebatch`.`id`, `notification_noticequeuebatch`.`pickled_data` FROM `notification_noticequeuebatch`; args=()
releasing lock...
released.
0 batches, 0 sent
done in 0.00 seconds
This is the code sending the Notice:
admin = User.objects.get(id=1)
notification.send_now([amin], "order_form_created", {"from_user": admin})
Notice settings looks right, my user is subscribed to this kind of notice. From what I understand the app looks in Notification Batches, which are always empty ..
Edit: Looks like the problem was the email server .. I used an external SMTP and it worked.
try notification.queue(..) instead of send_now(..) then python manage.py emit_notices
You are doing send_now() so why the emit_notices management command?