Python 如何从Django中的text/HTMLAPI响应中获取数据
我以Json格式向(FortPay支付网关)API发送post请求,并从同一URL获得文本/html格式的响应。。。 我需要的是获取这个响应中发送的数据,因为它包含一个我需要重用的令牌 这是我在views.py中的请求:Python 如何从Django中的text/HTMLAPI响应中获取数据,python,django,api,Python,Django,Api,我以Json格式向(FortPay支付网关)API发送post请求,并从同一URL获得文本/html格式的响应。。。 我需要的是获取这个响应中发送的数据,因为它包含一个我需要重用的令牌 这是我在views.py中的请求: def DayTourCreditInput(request, buyer_id): buyer = get_object_or_404(DayBuyer, id=buyer_id) redirectUrl ='https://checkout.payfort
def DayTourCreditInput(request, buyer_id):
buyer = get_object_or_404(DayBuyer, id=buyer_id)
redirectUrl ='https://checkout.payfort.com/FortAPI/paymentPage'
requestParams = {
'service_command ' : 'TOKENIZATION',
'********' : '********************' #etc.
}
r = requests.post(redirectUrl, params=requestParams)
content = r.text
return HttpResponse(content, content_type='text/plain')
##I Tried r.json and r.json() and also return
#HttpResponse(contentJson,
#content_type='application/json') ... But all raises errors
我寻找cgi-python,但是没有足够的文档可用,我不知道它是否适合这种情况
只想确保站点通过包含JavaScript的html文档进行响应 以下是PayFort的回复示例:
您好,您似乎已关闭JavaScript。请使其能够使用付款页面。
var resposneBo={“响应代码”:“00009”,“响应消息”:“无效商户标识符”,“堡垒id”:null,“令牌”:“15189DTowwMj9W59354916191697229893534”};
//-----------------导入可验证项----------------
var cancelOperation=“常规/取消操作”;
var cardStatusMissmatch=“1001”;
您能准确显示它返回的内容吗?如果它是敏感的,显示一个数据样本。我在@Azy\u CRW4282帖子中添加了结果。你能准确显示它返回的内容吗?如果是敏感的,显示一个数据样本,我在@Azy_Crw4282帖子中添加了结果
<!DOCTYPE html>
<html lang="en" class="body-background">
<noscript>
<div class="noscript-message">
<i class="icon-attention-circled"></i> Hello, you seem to have JavaScript turned off. Please enable it to use the payment page.
<div class="noscript-button-container">
<div class="noscript-button ">
<a href="http://www.enable-javascript.com/" target="_blank" class="">Show me how to enable it</a>
</div>
</div>
</div>
</noscript>
<head>
<input type="hidden" id="card_no_invalid_warrning_msgH"
value='Card number is <em>invalid.</em>'>
<input type="hidden" id="card_no_invalid_warrning_msgH"
value='Card number is <em>invalid.</em>'>
<input type="hidden" id="card_bin_suppressed_warrning_msgH"
value='This card is not supported for online purchases, please contact your bank for more information or use another card.'>
<input type="hidden" id="all_empty_warrning_msgH"
value='Fields marked in <em>red</em> are mandatory to proceed.'>
<!-- and also it contains scripts like that: -->
<script>
var resposneBo ={"response_code":"00009","response_message":"Invalid merchant identifier","fort_id":null,"token":"15189DTowwMj9W59354916191697229893534"};
//----------------- import veriables -----------------
var cancelOperation = "general/cancelOperation";
var cardStatusMissmatch = "1001";