HTTP Error 404: Not Found python urllib
我的代码是这样的:
1 2 3 4 5 6 7 8 9 | 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') |
我的网址有问题这是我的输出:
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
equest.py", line 223, in urlopen
return opener.open(url, data, timeout)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.py", line 532, in open
response = meth(req, response)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.py", line 564, in error
result = self._call_chain(*args)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.py", line 504, in _call_chain
result = func(*args)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.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
equest.py", line 532, in open
response = meth(req, response)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.py", line 570, in error
return self._call_chain(*args)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.py", line 504, in _call_chain
result = func(*args)
File"C:\Users\alext\AppData\Local\Programs\Python\Python36\lib\urllib
equest.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
我检查了网址,这绝对是正确的。 我见过其他人有这样的问题,但我仍然不确定解决方案。
你错过了一个/在城市之后和预测中的e。 它应该是
1 | url = 'http://www.weather-forecast.com/locations/'+city+'/forecasts/latest' |