I am currently trying to create a REST web service for my django site from scratch and I do not want to use external libraries as this is supposed to be a learning experience. One of my applications act as the web application while the other will act as the web service. I have plenty of examples on how to implement the web service and return Http responses but the problem is generating and sending http requests which I don’t have an example of. I want my application to send a http request to the other application which receives it and responds.
The web service responds perfectly to browser-generated request. I simply write the resource’s address in the address bar and I get the expected response.
I’ve tested using python’s built-in urllib2’s urlopen but it will hang forever, possibly because the socket is occupied. I do realize that I haven’t specified a time-out, but my concern is more that the request is never picked up by the server. There is no log of the request ever occurring. The url in code and in browser are identical.
Is there a way in django to simply generate a Httprequest and send it on its way without much fuss?
#This is the offending line.
response = urllib2.urlopen('http://127.0.0.1:8000/api/browse/')
This is just because the development server is single-threaded. It can’t both be responding to the original request from the client and the request that’s generated internally, so it will hang.