send http request using django and get results


This might seem like an extremely simple and stupid question yet i can’t find a convenient answer.
I’m trying to use google’s reverse geocodding api with django, as the website explains (at I’m supposed to send a request to the url :,-73.961452&key=<_api_key>
But I can’t find an appropriate way to send this request using django to google api.
To me it seems something so simple will be doable by some method built-in django but all I could find was modules to install.
If there’s no way but installing other python modules which one’s the best?


Well, the most straightforward way would be to install requests library and simply call:

result = requests.get(your_link)

You can find additional information (e.g., how to authenticate, use cookies, etc., as well as how to access data in response) in the library’s docs. The requests library is very well written, very intuitive and simple to use. Quite a lot of smart people and companies use it, too, so it’s not a half-baked library someone just hacked out over the weekend (as of this moment, it has 6060 commits and 595 contributors on GitHub).

If you absolutely must avoid external libraries, why not try urllib.request. It’s a bit more complicated, and even the docs themselves recommend using requests if you prefer higher-level interface. But you definitely can get the job done with it. To get started, you can read the docs on how to use it to fetch data. Read this thread for an example of how to extract json from a response you’d get with urllib.

Answered By – cegas

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published