Editing Community Data Science Course (Spring 2023)/Week 4 lecture notes
From CommunityData
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 109: | Line 109: | ||
* <code>import requests</code> imports the library so we can use it. | * <code>import requests</code> imports the library so we can use it. | ||
* <code>response = requests.get('http://nominatim.openstreetmap.org/', | * <code>response = requests.get('http://nominatim.openstreetmap.org/', {'q': '[bakery] near seattle wa', 'format': 'json'})</code> | ||
This is the most important line! Here, we "get" information from the web server. Note that we pass the url up to the "?" character as the first argument. Compare the dictionary second argument to the query we did above in our browser. How do they differ? How are they the same? | This is the most important line! Here, we "get" information from the web server. Note that we pass the url up to the "?" character as the first argument. Compare the dictionary second argument to the query we did above in our browser. How do they differ? How are they the same? | ||
* <code>print(response.status_code)</code>Β the response is a python object that contains the actual contents of the web page as well as some status information. Here, we're getting the status_code, which tells us whether the call succeeded. 200 is "good", and you will sometimes see 404 for "not found" or 500 for "server error". | * <code>print(response.status_code)</code>Β the response is a python object that contains the actual contents of the web page as well as some status information. Here, we're getting the status_code, which tells us whether the call succeeded. 200 is "good", and you will sometimes see 404 for "not found" or 500 for "server error". |