I have to make an HTTPS request in Python, and I am using the requests module to try to make my life easier.
The request needs to have a header and 3 FORM parameters URL encoded. This is what I am doing:
header = {'Content-type': 'application/x-www-form-urlencoded', 'Authorization':'Basic ' + encoded_string, 'Connection': 'Keep-Alive', 'Host':'host.host.com'}
payload='grant_type=authorization_code&code=' + request.args['code'] + '&state=' + request.args['state'] + '&redirect_uri=http://xxx.xyz.com/request_listener'
url = 'https://serviceprovider.xxx.com/auth/j_oauth_resolve_access_code'
response = requests.post(url, data=payload, headers=header, verify=False)
When I try to return the content
or text
of the response
, I get an empty string. However, when I print the actual response
object, it says it is a <Response [200]>
, but if this were actually a 200 OK then the server I am POSTing too should go to the redirect_uri I have specified and I would get a notification there.
This is not happening, and I am mystified as to why.
curl
to construct a request by hand, to make sure that you know what the contents of a valid request should be. If that works, then you know that there is a problem with the way you are building or delivering the request in Python. Construct thepayload
as a dict rather than a string. Try building a prepared request so you can examine the request state before sending it to the server. – Tim Pierce Dec 10 '13 at 4:21