# importing the requests library import requests # api-endpoint URL = "http://maps.googleapis.com/maps/api/geocode/json" # location given here location = "delhi technological university" # defining a params dict for the parameters to be sent to the API PARAMS = {'address':location} # sending get request and saving the response as response object r = requests.get(url = URL, params = PARAMS) # extracting data in json format data = r.json() # extracting latitude, longitude and formatted address # of the first matching location latitude = data['results'][0]['geometry']['location']['lat'] longitude = data['results'][0]['geometry']['location']['lng'] formatted_address = data['results'][0]['formatted_address'] # printing the output print("Latitude:%s\nLongitude:%s\nFormatted Address:%s" %(latitude, longitude,formatted_address))I am getting following error for the above code.
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
Error:Traceback (most recent call last):
File "C:\Users\SAIRAM\Desktop\Python\Lattitude Longitude.py", line 3, in <module>
File "C:\Users\SAIRAM\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\__init__.py", line 120, in <module>
from . import utils
File "C:\Users\SAIRAM\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\utils.py", line 27, in <module>
from ._internal_utils import to_native_string
File "C:\Users\SAIRAM\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\_internal_utils.py", line 11, in <module>
from .compat import is_py2, builtin_str, str
File "C:\Users\SAIRAM\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\compat.py", line 61, in <module>
from http.cookies import Morsel
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 779, in exec_module
File "<frozen importlib._bootstrap_external>", line 915, in get_code
File "<frozen importlib._bootstrap_external>", line 973, in get_data
OSError: [Errno 9] Bad file descriptor
I am getting this error whenver I try to read the data from website. Even when try to install python packages using pip and when I try to open a software created by python, I am getting the same error. Please help me.