Python and curl questions

I will pass the purchase information (e.g. CC) to the bank gateway and get the result using Django in this way through Python.

What would be an effective and safe way to do this?

I read the documentation for this gateway for php, they seem to use this method:

$xml= Some xml holding data of a purchase. $curl = `/usr/bin/curl -s -d 'DATA=$xml' "https://url of the virtual bank POS"`; $data=explode("\n",$curl); //return value is also an xml, seems like they are splitting by each `\n` 

and using $ data, they process if the payment is accepted, rejected, etc.

I want to achieve this in python, for this I did a few searches and there seems to be a python curl app called pycurl so far I have no experience using curls and don't know if this library is suitable for this task. Keep in mind that since this transfer requires security, I will use SSL.

Any suggestion would be appreciated.

+4
source share
2 answers

Using the standard urllib2 library urllib2 should be enough:

 import urllib import urllib2 request_data = urllib.urlencode({"DATA": xml}) response = urllib2.urlopen("https://url of the virtual bank POS", request_data) response_data = response.read() data = response_data.split('\n') 

I assume the xml variable contains the data to send.

+10
source

Referring to pycurl.sourceforge.net:

To summarize, PycURL is very fast (especially for several concurrent operations) and very functional, but has a somewhat complicated interface. If you need something simpler or prefer a clean Python module, you can check urllib2 and urlgrabber. There is also a good comparison of different libraries.

Both curl and urllib2 can work with https, so it is up to you.

+3
source

Source: https://habr.com/ru/post/1302147/


All Articles