avatar Bite 111. Use the ipinfo API to lookup IP country

In this Bite you will use the requests library to make a GET request to the ipinfo service.

Use IPINFO_URL and parse the (2 char) country code from the obtained json response.

Note how we mocked out the requests.get call in the tests, you can see another example of this in our Parsing Twitter Geo Data and Mocking API Calls by Example article.

Querying APIs is a common need so this should become second nature :) - enjoy!

Login and get coding
go back Intermediate level
Bitecoin 3X

230 out of 231 users completed this Bite.
Will you be Pythonista #231 to crack this Bite?
Resolution time: ~25 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 1.9 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help