2

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.open(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.

1
  • 1
    Ahem try going to http://www.weather-forecast.com/locations/Paris/forcasts/latest Maybe you should have triple-checked. Commented Feb 28, 2018 at 17:26

1 Answer 1

1

you are missing a / after the city and a e in forecast. It should be

url = 'http://www.weather-forecast.com/locations/'+city+'/forecasts/latest'
Sign up to request clarification or add additional context in comments.

1 Comment

I also missed that you need a e in forecasts, so it is url = 'http://www.weather-forecast.com/locations/'+city+'/forecasts/latest'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.