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
#2
Odd error. Looks like the import requests is failing, but it's failing not at the python level but in the OS in an odd way. It's almost like your installation or the hard disk is corrupt.

I'd probably try running this on another machine, or maybe trying a separate python install to see if that would work.
Reply
#3
As mention bye @bowlofred it can be a problem with your installation.
Try from cmd:
python -m pip install --upgrade pip 
pip -V
pip show requests
If get same error on any of this,the easiest may be to reinstall Python.
Can also try running as administrator.
Python 3.8 (3.6-3.7) and pip installation under Windows.
If follow tutorial over can also try an other placement that AppData\Local,i do not like the long default Path.
Reply
#4
I tried all your inputs but nothing works. I tried to install the python in different drive. But the same error is coming. I will agree with you that it's OS error. Few days back its working perfectly. But now only I am getting this error. Can you please help me how to rectify this OS error.
Reply


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,788 Aug-29-2020, 03:23 AM
Last Post: Base12
  How to split and combine embedded lines using less code pjfarley3 6 2,416 Aug-13-2020, 09:13 PM
Last Post: pjfarley3
  [split] SyntaxError when trying to execute code on Windows nehaya 2 1,963 Aug-04-2020, 11:18 AM
Last Post: nehaya
  [split] need help with the code CERO123 2 1,850 Feb-10-2020, 03:32 PM
Last Post: jefsummers
  [split] VS Code Editor SupaNub 5 2,807 Nov-27-2019, 03:37 PM
Last Post: snippsat
  [split] I need help making a four digit code cracker with random tycpytyt 1 2,515 Mar-24-2019, 05:53 PM
Last Post: micseydel
  [split] Paspberry Pi and Python - how to write code soona 1 2,280 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