Django-Paypal IPN 403 错误

发布于 2024-12-03 00:24:04 字数 1044 浏览 3 评论 0原文

我正在研究 paypal ipn 监听器 - 它似乎没有“听到”信号,尽管数据库已更新,所以我知道该 ipn 已被 paypal.standard.ipn 包接受。

现在我从 ipn 模拟器收到 403 错误 - 有人知道为什么会发生这种情况吗?当我直接导航到侦听器 url 时,没有错误。

我将 @csrf_exempt 添加到侦听器,但这没有帮助。

欢迎任何建议。

Listeners.py:

from django.dispatch 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

正如您所看到的,所有应该发生的事情都是一些调试,但它没有实现。

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.dispatch 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南街女流氓 2024-12-10 00:24:04

我刚刚又遇到了同样的问题。如果其他人遇到此问题,这里是解决方案:

需要将 @csrf_exempt 添加到 django-paypal 包本身。

在 paypal/standard/ipn/views.py 中添加:

from django.views.decorators.csrf import csrf_exempt

在顶部、其余导入之间以及

@csrf_exempt

函数声明上方的 @require_POST 上方。

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.

虚拟世界 2024-12-10 00:24:04

这是一个很晚的答案,但我遇到了完全相同的问题。事实证明,我们没有关闭服务器上的 apache 基本身份验证(该身份验证在开发过程中已就位)。 PayPal 无法通过该身份验证层,因此会收到 403 响应。这可能是另一个问题,但这肯定是我们的问题!

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!

我的黑色迷你裙 2024-12-10 00:24:04

我有同样的问题。
事实证明,在我的 virtualenv 中,我已经安装了 django-paypal,并且在我的项目中,我有应用程序paypal
当我将 @csrf_exempt 添加到我的应用程序时不起作用,因为 django 总是在我的 Virtualenv 中调用 paypal 包。
我做了一个 pip uninstall django-paypal ,一切顺利(另一个解决方案可能是修改包视图)

我希望它有帮助!

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!

心清如水 2024-12-10 00:24:04

这也可能是由于您的 urls.py 布局所致。我很愚蠢,为默认主页登陆页面使用了“^”正则表达式。当我将 iPN url 切换到该语句之前时,一切正常。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文