【发布时间】:2011-10-22 06:37:08
【问题描述】:
我正在尝试使用我的 Twisted 服务器上的 Apple 商店服务器验证应用内购买的交易收据。我已将(SKPaymentTransaction *)transaction.transactionReceipt 从我的应用程序发送到我的服务器。
但是现在,将 JSON 对象发送到 Apple 服务器时,我不断收到来自 Agent.request() 的 Deferred 中未处理的错误。我怀疑这是因为我没有在端口 443 上监听 Apple 商店的响应,但我不希望我的应用程序也与端口 443 上的 Twisted 服务器通信。这是我的代码:
from twisted.application import internet, service
from twisted.internet import protocol, reactor
from zope.interface import implements
from twisted.web.iweb import IBodyProducer
from twisted.internet import defer
from twisted.web.client import Agent
from twisted.web.http_headers import Headers
import json
import base64
class StringProducer(object):
implements(IBodyProducer)
def __init__(self, body):
self.body = body
self.length = len(body)
def startProducing(self, consumer):
consumer.write(self.body)
return succeed(None)
def pauseProducing(self):
pass
def stopProducing(self):
pass
def printResponse(response):
print response # just testing to see what I have
def httpRequest(url, values, headers={}, method='POST'):
agent = Agent(reactor)
d = agent.request(method,
url,
Headers(headers),
StringProducer(values)
)
d.addCallback(printResponse)
class storeServer(protocol.Protocol):
def dataReceived(self, data):
receiptBase64 = base64.standard_b64encode(data)
jsonReceipt = json.dumps({'receipt-data':receiptBase64})
print jsonReceipt # verified that my data is correct
d = httpRequest(
"https://buy.itunes.apple.com/verifyReceipt",
jsonReceipt,
{'Content-Type': ['application/x-www-form-urlencoded']}
)
factory = protocol.Factory()
factory.protocol = storeServer
tcpServer = internet.TCPServer(30000, factory)
tcpServer.setServiceParent(application)
如何解决此错误?我是否必须创建另一个侦听端口 443 的服务?如果是这样,我如何让连接到我的应用程序的服务与通过 https 连接的服务通信?
【问题讨论】:
-
你没有说你得到了什么错误,只是你得到了一个。您应该始终包含完整的错误文本(回溯和异常)。
-
这是我得到的错误:
2011-10-22 17:09:32-0400 [-] Unhandled error in Deferred: 2011-10-22 17:09:32-0400 [-] Unhandled Error Traceback (most recent call last): Failure: twisted.web._newclient.RequestGenerationFailed: [<twisted.python.failure.Failure <type 'exceptions.NameError'>>]
标签: iphone python https in-app-purchase twisted