How post data over https with urllib2? - django

I want to integrate a credit card processing in my website using Paybox.com API's.
I have to send a POST request (using urllib2) to Paybox API's with credit card details (number, date, cvv) when a user submit a form.
How can I secure that? is it enougth to put https://www.mywebsite.com/card/processing in my form action?
How can I send POST data over HTTPS using urllib2?
PS: I work on Django.

Well in terms of security refer to this QA: POST data encryption - Is HTTPS enough?
As far as how to do it, here's an explanation about using urllib: http://www.codercaste.com/2009/11/28/how-to-use-the-urllib-python-library-to-fetch-url-data-and-more/
The idea is to use the urlencode command to create a parameters object for the request, then create a request object from the url and the parameters object, and then call urlopen on the request object in order to actually send the request.

Here are solutions using python-request lib: http://www.python-requests.org/en/latest/user/advanced/
request using ssl: http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification
request using post: http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests (should also allow verify=True parameter)
By the way, python-request is a very powerful and easy way to make requests.

Related

Tandem - Is there an equivalent to cURL in HP NonStop?

I need to execute a simple HTTP POST to a URL from the NonStop computer to make sure a service functions correctly. Is there a way to do this?
Use the built-in TACL commands to make an HTTP POST request. The TACL command POST allows you to send an HTTP POST request to a specified URL. For example:
POST url headers=content-type:text/plain
data=This is the request body

How do I send an HTTP post request with headers and json data through a proxy with WinHTTP (C++)

I am attempting to send a post request like the one described in the title, but I cannot seem to find a good example of a generic piece of code. My work on my project is a bit tedious as I have never used WinHTTP, only libcurl before which is why I decided to ask here. To reiterate, the http request is a post request with specific header values and json data in the request body which is sent through a proxy to a website using winHTTP. If anyone could provide me with assistance, it would be greatly appreciated.

How to send POST variable in POSTMAN

I can't get POSTMAN to send any post variables to my Django app. Suppose I have a post variable called 'report_request' and it has a value that is a JSON string. On the Django side I want to get request.POST['report_request'] and parse the JSON into a dictionary. But POSTMAN never seems to send the POST data. How exactly do I do this? Is there some magical header I need to send?
Doh! My bad. The URL I need to connect to is really HTTPS rather than HTTP, but I was specifying the URL as http://. Apparently if Postman is asked to connect to an HTTPS site using HTTP, it silently just drops all POST variables. How lovely. Anyway it was an easy fix, just change the http:// url to https:// and all is well.
Be sure to provide the POST data in the body (body tab) of the request and not in the parameters (params tab).
Otherwise, POSTMAN will interpret your POST request as being without data and on a url with GET parameters.
See these specifications about csrf if needed
Check if you're sending the csrf token, it's a security feature.
https://docs.djangoproject.com/en/1.8/ref/csrf/

Collect POST data, process it and POST that data to an external URL

I'm trying to implement a data processing module.
The scenario is,
First a user will POST some data.
User POSTed data needs to be processed and some more info needs to be added here
This processed POST data should be sent to an external URL with out user intervention.
The external URL will accept only POST requests.
Please suggest me a way to send this POST data to external URL.
Update
As suggested, I started using requests.
In the view that i collected the initial POST data, I'm compiling another data object with the user posted data (after processing) and adding some more data to the object and doing the post request as bellow
req = requests.post(post_url, data=post_obj)
the status_code returned is 200
But the data(post_obj) doesn't seem to be sent to the post_url. The post_url is prompting that it did not receive the POST data.
when I checked the req object,
req.request.data seems to have the post_obj information and req.request.url has the post_url
req.url has the redirect_url which is prompting that the post_url didn't receive any data.
My question is,
How to actually POST the data?
what is the object that needs to be returned in the view?
If the way I'm POSTing the data (requests.post method) is wrong. Please suggest me the appropriate way.
Note: After POSTing the data to the post_url, it will be redirected to a different page.
Use Urllib2, mechanise or requests (who all use pythons built in urllib2 and httplib) or pycurl (which uses libcurl) to do the posts to the external resource.
Requests is the easiest to work with, mechanize is great for filling out forms and programming like a browser, urllib2 is the underlying library so it's also important to know and pycurl is (imo) a last resort due to not being particularly maintained
You should consider using a queue to handle the server->third party step and then asynchronously report to the user that the task has completed, otherwise you face potentially timing your connections out if your 3rd party app takes to long to respond.
You can use the standard library urllib2 to do the 2nd POST.
I've also heard good things about the requests library, which should be easier to use than urllib2.

Connecting a desktop application with a website

I made an application using Qt/C++ that reads some values every 5-7 seconds and sends them to a website.
My approach is very simple. I am just reading the values i want to send and then i make an HTTP POST to the website. I also send the username and password to the website.
The problem is that i cannot find out if the request is successful. I mean that if i send the request and server gets it, i will get an HTTP:200 always. For example if the password is not correct, there is no way to know it. It is the way HTTP works.
Now i think i will need some kind of a protocol to take care the communication between the application and the website.
The question is what protocol to use?
If the action performed completes before the response header is sent you have the option of adding a custom status to it. If your website is built on PHP you can call header() to add the custom status of the operation.
header('XAppRequest-Status: complete');
if you can modify the server side script you could do the following
on one end :
You can make the HTTP post request via ajax
and evaluate the result of the ajax request.
On the serve side
On the HTTP request you do your process and if everything goes accordingly you can send data back to the ajax script that called it.
solves your problem .. ?