开发者

Django-Paypal IPN 403 Error

I was working on the paypal ipn listener - it didn't seem to be 'hearing' the signals, although the database was updated so I know the ipn was accepted by the paypal.standard.ipn package.

Now I get a 403 error from the ipn simulator - does anyone have any idea why this would happen? When I navigate directly to the listener url there is no error.

I added @csrf_exempt to the listener, but that didn't help.

Any suggestions are welcome.

Listeners.py:

from django.dispat开发者_JAVA技巧ch import receiver
from django.contrib.sites.models import Site

from django.views.decorators.csrf import csrf_exempt
from paypal.standard.ipn import signals as paypal_signals
from messaging import send
from utests.models import Test
 import logging


@csrf_exempt
@receiver(paypal_signals.payment_was_successful)
def payment_was_succesful_listener(sender, **kwargs):
     #:sender is the PayPalIPN model instance
    logging.debug("in payment successful listener")
    ... the rest of the code is commented out while I debug...


@receiver(paypal_signals.payment_was_flagged, dispatch_uid="dl-payment_was_flagged")
def payment_was_flagged_listener(sender, **kwargs):
    #:sender is the PayPalIPN model instance
    pass

As you can see, all that is supposed to happen is some debugging, but it doesn't get there.


I just ran into the same issue again. Here is the solution in case anyone else has this problem:

The @csrf_exempt needs to be added to the django-paypal package itself.

In paypal/standard/ipn/views.py add:

from django.views.decorators.csrf import csrf_exempt

at the top, among the rest of the imports, and

@csrf_exempt

above the @require_POST above the function declaration.


This is a very late answer, but I had exactly the same problem. Turns out we hadn't turned off the apache Basic Authentication on our server (which was in place during development). PayPal can't get through that authentication layer, so gets a 403 in response. It could have been another issue, but this was certainly our problem!


I had the same issue. It turns out that in my virtualenv I have installed django-paypal and in my project, I had the app paypal. When I add the @csrf_exempt to my app didn't work, because django always call the paypal package in my Virtualenv. I did an pip uninstall django-paypal and everything goes well (Another solution maybe is modify the package view)

I hope it helps!


It could also be due to your urls.py layout. I was dumb enough to have a '^' regex for a default home landing page. When I switched the ipn url to be before that statement everything worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜