我正在尝试从 Amazon FPS 获取付款结果信息,该信息有两种形式:
- 用户使用 GET 和查询字符串参数重定向到原始服务器
- 亚马逊将 POST 发送到具有匹配参数的原始服务器
我不能保证哪个请求会首先到达服务器,所以我通过序列化request.GET
或request.POST
使用将第一个请求存储在数据库中json.dumps
,然后尝试稍后加载它json.loads
以与另一个请求进行比较:
初始请求:
type = request.META['REQUEST_METHOD']
sub_req = SubscriptionRequest()
params = getattr(request, type)
serialized_params = json.dumps(params)
if type == 'GET': sub_req.client_params = serialized_params
if type == 'POST': sub_req.server_params = serialized_params
sub_req.save()
跟进请求:
stored_params = json.load(sub_req.server_params if type == "GET" else sub_req.client_params)
错误:
File "/var/www/test.com/htdocs/apps/subscription/services.py", line 147, in subscription_request_check_or_store
stored_params = json.load(sub_req.server_params if type == "GET" else sub_req.client_params)
File "/usr/lib/python2.7/json/__init__.py", line 274, in load
return loads(fp.read(),
AttributeError: 'unicode' object has no attribute 'read'