Jan-07-2021, 02:43 PM
(This post was last modified: Jan-07-2021, 02:43 PM by PythonNoob1998.)
Hi, so I am trying to run this script -
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!
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!