Working with requests app

45 views
Skip to first unread message

Jorge Andrés Vergara Ebratt

unread,
Nov 2, 2014, 6:36:50 PM11/2/14
to django...@googlegroups.com
Hello everyone,

I'm working with requests app so I can send post data in one of my views, I need to sent it to an external url, I'm integrating with an online payment provider.

I'm doing as the docs say:

import requests

def realizarPago(request):
    parametros_payu = {I use my params here in a dict}

    (That's PayU's default url to stage a payment request)

    return requests.post(url, data = parametros_payu)



When I was using the testing url I got the SSL not verified error, and I tried in my browser and I could see their certificate was broken, now I'm trying the production url, the certificate is ok, and I instead get the error:
'Response' object has no attribute 'get'

I'm using:
django 1.7.1
python 3.4.0

Any help would be very appreciated

--
Jorge Andres Vergara Ebratt
#SoftwareDeveloper (Or at least trying to be)
@javebratt

Collin Anderson

unread,
Nov 2, 2014, 8:56:25 PM11/2/14
to django...@googlegroups.com
Hello,

Does this work?

def realizarPago(request):
    parametros_payu
= {} # I use my params here in a dict
    url
= "https://gateway.payulatam.com/ppp-web-gateway/"
   
return HttpResponse(requests.post(url, data=parametros_payu).text)

Collin

Jorge Andrés Vergara Ebratt

unread,
Nov 3, 2014, 7:19:26 AM11/3/14
to django...@googlegroups.com
Nope, no good.

I was looking to see if there was something like this posted in the group before and there was, I found this answer from 2009:

"This is impossible to redirect a user to external site with post. 
urllib and urllib2 can only help to fetch data, but not to redirect a 
user."

Anyone knows if that's really the case? I can just do what most people do to integrate the online payment solution, create a form with action to their website and have all my fields as 'hidden'. But I was wondering if there is a way to actually send the data via POST from inside a django view

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/19f76a8a-e90e-49ca-abb0-e9c8d1a003b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Collin Anderson

unread,
Nov 3, 2014, 8:12:59 AM11/3/14
to django...@googlegroups.com
Hello,
 
"This is impossible to redirect a user to external site with post. 
urllib and urllib2 can only help to fetch data, but not to redirect a 
user."
You can't do a 301 or 302 http redirect, but I don't think that's what you're trying to do.

Anyone knows if that's really the case? I can just do what most people do to integrate the online payment solution, create a form with action to their website and have all my fields as 'hidden'. But I was wondering if there is a way to actually send the data via POST from inside a django view

It is possible to send data via POST inside a django view. I think the issue with your code is the return statement. It seems to me you are successfully sending a POST from your view, but you then need to do something with that response, and then return a django HttpResponse (or render a template) to the user.

Collin

Jorge Andrés Vergara Ebratt

unread,
Nov 3, 2014, 8:47:28 AM11/3/14
to django...@googlegroups.com
I checked, it's sending the POST data, but what I need is to redirect the user to the external site WITH the post data... So I think I'm going with the form + hidden fields solution

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages