Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Request Errors
#1
Hi, so I am trying to run this script -

import requests, json 

# Enter your API key here 
api_key = "2eacaa2c66e011c77935d17f0b7a72ed"

# base_url variable to store url 
base_url = "http://api.openweathermap.org/data/2.5/weather?"

# Give city name 
city_name = input("Enter city name : ") 

# complete_url variable to store 
# complete url address 
complete_url = base_url + "appid=" + api_key + "&q=" + city_name 

# get method of requests module 
# return response object 
response = requests.get(complete_url) 

# json method of response object 
# convert json format data into 
# python format data 
x = response.json() 

# Now x contains list of nested dictionaries 
# Check the value of "cod" key is equal to 
# "404", means city is found otherwise, 
# city is not found 
if x["cod"] != "404": 

	# store the value of "main" 
	# key in variable y 
	y = x["main"] 

	# store the value corresponding 
	# to the "temp" key of y 
	current_temperature = y["temp"] 

	# store the value corresponding 
	# to the "pressure" key of y 
	current_pressure = y["pressure"] 

	# store the value corresponding 
	# to the "humidity" key of y 
	current_humidiy = y["humidity"] 

	# store the value of "weather" 
	# key in variable z 
	z = x["weather"] 

	# store the value corresponding 
	# to the "description" key at 
	# the 0th index of z 
	weather_description = z[0]["description"] 

	# print following values 
	print(" Temperature (in kelvin unit) = " +
					str(current_temperature) +
		"\n atmospheric pressure (in hPa unit) = " +
					str(current_pressure) +
		"\n humidity (in percentage) = " +
					str(current_humidiy) +
		"\n description = " +
					str(weather_description)) 

else: 
	print(" City Not Found ") 
But I am getting these errors, when I try to run them in the terminal -

Error:
Traceback (most recent call last): File "Weather_Map.py", line 8, in <module> import requests, json File "/Users/marcholder/opt/anaconda3/lib/python3.8/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/Users/marcholder/opt/anaconda3/lib/python3.8/site-packages/urllib3/__init__.py", line 8, in <module> from .connectionpool import ( File "/Users/marcholder/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 11, in <module> from .exceptions import ( File "/Users/marcholder/opt/anaconda3/lib/python3.8/site-packages/urllib3/exceptions.py", line 2, in <module> from .packages.six.moves.http_client import ( 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 655, in _load_unlocked File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible File "/Users/marcholder/opt/anaconda3/lib/python3.8/site-packages/urllib3/packages/six.py", line 203, in load_module mod = mod._resolve() File "/Users/marcholder/opt/anaconda3/lib/python3.8/site-packages/urllib3/packages/six.py", line 115, in _resolve return _import_module(self.mod) File "/Users/marcholder/opt/anaconda3/lib/python3.8/site-packages/urllib3/packages/six.py", line 82, in _import_module __import__(name) File "/Users/marcholder/opt/anaconda3/lib/python3.8/http/client.py", line 71, in <module> import email.parser File "/Users/marcholder/opt/anaconda3/lib/python3.8/email/parser.py", line 12, in <module> from email.feedparser import FeedParser, BytesFeedParser File "/Users/marcholder/opt/anaconda3/lib/python3.8/email/feedparser.py", line 27, in <module> from email._policybase import compat32 File "/Users/marcholder/opt/anaconda3/lib/python3.8/email/_policybase.py", line 9, in <module> from email.utils import _has_surrogates File "/Users/marcholder/opt/anaconda3/lib/python3.8/email/utils.py", line 33, in <module> from email._parseaddr import quote File "/Users/marcholder/opt/anaconda3/lib/python3.8/email/_parseaddr.py", line 16, in <module> import time, calendar File "/Users/marcholder/python/calendar.py", line 4, in <module> holidays = hapi.holidays({ File "/Users/marcholder/opt/anaconda3/lib/python3.8/site-packages/holidayapi/__init__.py", line 16, in holidays response = requests.get(url, params=parameters); AttributeError: partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import)
Or, when I run the script via the terminal in the Visual Studio Code editor, I get this -

Error:
Traceback (most recent call last): File "Weather_Map.py", line 8, in <module> import requests, json ImportError: No module named requests
This started happening yesterday, and I am not completely sure why. I don't know if it is worth noting, but I downloaded Python3.9 yesterday (I was previously using 3.8, although judging by some of these errors, it looks like I am still using 3.8?), could this be an issue? And if so, how do I rectify this? These errors also seems to happen when I try to run other Python files, which previously worked.

The implication of the second error I have posted is that I have not installed requests on the terminal, but I did, and that error still came up. I installed requests for both terminals used.

I hope that all makes sense.

Any help would be much appreciated!
Reply


Messages In This Thread
Python Request Errors - by PythonNoob1998 - Jan-07-2021, 02:43 PM
RE: Python Request Errors - by Axel_Erfurt - Jan-07-2021, 02:43 PM
RE: Python Request Errors - by PythonNoob1998 - Jan-07-2021, 02:47 PM
RE: Python Request Errors - by buran - Jan-07-2021, 02:59 PM
RE: Python Request Errors - by PythonNoob1998 - Jan-07-2021, 03:12 PM
RE: Python Request Errors - by ndc85430 - Jan-07-2021, 03:17 PM
RE: Python Request Errors - by Axel_Erfurt - Jan-07-2021, 04:41 PM
RE: Python Request Errors - by buran - Jan-07-2021, 05:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  When does Python detect Errors? stamp1t 1 532 Oct-21-2023, 05:53 PM
Last Post: deanhystad
  how can I correct the Bad Request error on my curl request tomtom 8 5,317 Oct-03-2021, 06:32 AM
Last Post: tomtom
  Rmarkdown opened by python code - errors Rav013 0 2,167 Apr-27-2021, 03:13 PM
Last Post: Rav013
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 4,031 Jun-18-2020, 08:07 AM
Last Post: buran
  Pip Syntax Errors in CMD: Windows 10 and Python 3.8.1 jamesphopper 2 4,584 Feb-08-2020, 07:21 PM
Last Post: jamesphopper
  Python stops without errors shahgourav 4 2,883 Feb-04-2020, 11:44 PM
Last Post: micseydel
  Can the comments produce errors in python? newbieAuggie2019 9 4,540 Nov-26-2019, 12:19 AM
Last Post: micseydel
  Running into errors when installing pip and pip3 on python 2.7 and python 3.6 tej7gandhi 1 2,927 May-05-2019, 10:37 PM
Last Post: snippsat
  Does Python sqlite3 detect connection errors zatlas1 6 4,152 Jan-18-2019, 06:02 AM
Last Post: zatlas1
  Errors in Python dttomoum 1 2,774 May-23-2018, 08:57 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