错误:[Errno 32] 管道破裂,PayPal回调Python Django应用时

3 投票
2 回答
2897 浏览
提问于 2025-04-16 06:08

你好,我正在把PayPal集成到我的Django应用中。

我使用的是最新版本的Django和Python 2.6。

不过,我发现每次PayPal的沙盒环境访问我的通知网址时,我的Django程序都会出现500 [Errno 32] Broken pipe的错误。

有没有人遇到过类似的情况?

谢谢!

Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 281, in run
    self.finish_response()
  File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 321, in finish_response
    self.write(data)
  File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 417, in write
    self._write(data)
  File "/usr/lib/python2.6/socket.py", line 318, in write
    self.flush()
  File "/usr/lib/python2.6/socket.py", line 297, in flush
    self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 104] Connection reset by peer
----------------------------------------
Exception happened during processing of request from ('216.113.191.33', 21736)
Traceback (most recent call last):
  File "/usr/lib/python2.6/SocketServer.py", line 283, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 309, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 562, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "/usr/lib/python2.6/SocketServer.py", line 618, in __init__
    self.finish()
  File "/usr/lib/python2.6/SocketServer.py", line 661, in finish
    self.wfile.flush()
  File "/usr/lib/python2.6/socket.py", line 297, in flush
    self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
----------------------------------------

2 个回答

0

这里有两个问题。首先,有些paypal的接口(特别是MassPay)实在是太差了。

第二个,更可能的问题是,你的服务器是单线程的,可能在向paypal正确抛出异常时遇到了麻烦。我曾经通过创建一个带表单的html文件(使用POST方式),模拟paypal的IPN,然后查看调试结果(或者更好的是,使用像PyDev这样的调试工具)来解决了类似的问题。当然,你也可以用curl来做同样的事情。

0

第一个错误Connection reset by peer的意思是连接被对方关闭了(在你的情况下是Pypal)。而Broken pipe这个错误则是因为连接突然关闭了,但没有提前通知另一方(在你的情况下是你的电脑)。

撰写回答