Answer the question
In order to leave comments, you need to log in
Analogue of php fopen(url with context) in python?
Good afternoon! I have the following php code, please help me translate it into python:
$url = "https://test.ctpe.net/frontend/GenerateToken";
$data = "AMOUNT=4.00&MODE=INTEGRATOR_TEST";
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
$response = @stream_get_contents($fp);
payload = {
"TRANSACTION.MODE": "INTEGRATOR_TEST",
"PRESENTATION.AMOUNT": "4.00"
}
url = "https://test.ctpe.net/frontend/GenerateToken"
post_data = urllib.urlencode(payload)
req = requests.post(url, data=post_data)
response = req.text
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question