Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Python code help
#1
# 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.
Reply


Messages In This Thread
[split] Python code help - by sairam17519 - Sep-10-2020, 01:23 AM
RE: [split] Python code help - by bowlofred - Sep-10-2020, 05:04 AM
RE: [split] Python code help - by snippsat - Sep-10-2020, 06:05 AM
RE: [split] Python code help - by sairam17519 - Sep-10-2020, 01:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Explain the python code in this definition Led_Zeppelin 1 711 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  [split] Kera Getting errors when following code example Image classification from scratch hobbyist 3 4,546 Apr-13-2021, 01:26 PM
Last Post: amirian
  How to Split Output Audio on Text to Speech Code Base12 2 6,784 Aug-29-2020, 03:23 AM
Last Post: Base12
  How to split and combine embedded lines using less code pjfarley3 6 2,410 Aug-13-2020, 09:13 PM
Last Post: pjfarley3
  [split] SyntaxError when trying to execute code on Windows nehaya 2 1,959 Aug-04-2020, 11:18 AM
Last Post: nehaya
  [split] need help with the code CERO123 2 1,847 Feb-10-2020, 03:32 PM
Last Post: jefsummers
  [split] VS Code Editor SupaNub 5 2,806 Nov-27-2019, 03:37 PM
Last Post: snippsat
  [split] I need help making a four digit code cracker with random tycpytyt 1 2,512 Mar-24-2019, 05:53 PM
Last Post: micseydel
  [split] Paspberry Pi and Python - how to write code soona 1 2,276 Mar-19-2018, 11:02 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020