My code is this:
import urllib.request
import re
http://www.weather-forecast.com/locations/Paris/forcasts/latest
city = input('Please enter a place: ')
url = 'http://www.weather-forecast.com/locations/'+city+'forcasts/latest'
data = urllib.request.urlopen(url).read()
data1 = data.decode('utf-8')
I'm having trouble with the url this is my output:
Traceback (most recent call last): File "C:/Users/alext/AppData/Local/Programs/Python/Python36/Weather forecast.py", line 9, in data = urllib.request.urlopen(url).read() File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 223, in urlopen return opener.open(url, data, timeout) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 532, in open response = meth(req, response) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 642, in http_response 'http', request, response, code, msg, hdrs) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 564, in error result = self._call_chain(*args) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 504, in _call_chain result = func(*args) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 756, in http_error_302 return self.parent.o pen(new, timeout=req.timeout) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 532, in open response = meth(req, response) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 642, in http_response 'http', request, response, code, msg, hdrs) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 570, in error return self._call_chain(*args) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib\\request.py", line 504, in _call_chain result = func(*args) File "C:\\Users\\alext\\AppData\\Local\\Programs\\Python\\Python36\\lib\\urllib \\request.py", line 650, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found
I have checked the url and it is definitely correct. I have seen others with problems like this but am still unsure as to the solution.
you are missing a / after the city and ae in forecast. It should be
url = 'http://www.weather-forecast.com/locations/'+city+'/forecasts/latest'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.