ChunkedEncodingError with requests python

0

I am trying to connect to an API to receive data that I will use in my app. I use Django 1.9 next to Python 2.7 and I have the project mounted locally with the Apache server, using the < strong> mod_wsgi .

To make requests to the API I use requests , but when I make a post request, passing a code that I get in a previous request and a cookie, Django gives me error:

  

ChunkedEncodingError "Connection broken: error (10054, 'The interruption of an existing connection has been forced by the remote host')

I've been searching the internet about it and the truth is that it's not clear to me if it's from mod_swgi, if django can not read chunked response ... and I can not find a solution to the problem. I have also looked at the Apache log, but no related error appears.

I have other get and post requests and none of them give me this error ... This is the line in django that gives me the error:

header = {'Content-Type':'application/x-www-form-urlencoded','Cookie':cookie}

requests.post('http://direccionapi.es/auth/OAuth20/Token',{'Authorization':'Basic d2Vdfdsfdf','code':codigo,'grant_type':'authorization_code','redirect_uri':ip,'response_type': 'code'},headers = header)

Someone who knows what is happening and some solution?

    
asked by Nieves R. 30.05.2017 в 11:51
source

1 answer

0

I think the post() method needs to pass the parameters to it as data= . Also, I think the Authorization key should go in the header, not the body.

header = {
    'Content-Type':'application/x-www-form-urlencoded',
    'Cookie':cookie,
    'Authorization':'Basic d2Vdfdsfdf'
}

requests.post('http://direccionapi.es/auth/OAuth20/Token',data={'code':codigo,'grant_type':'authorization_code','redirect_uri':ip,'response_type': 'code'},headers=header)
    
answered by 30.05.2017 в 14:12