简体   繁体   English

HTTP错误404:找不到python urllib

[英]HTTP Error 404: Not Found python urllib

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: 我在url上遇到问题,这是我的输出:

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 追溯(最近一次通话):文件“ C:/ Users / alext / AppData / Local / Programs / Python / Python36 / Weather Forecast.py”,第9行,数据= urllib.request.urlopen(url).read( )文件“ C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py”,第223行,位于urlopen返回opener.open(URL,数据,超时)中,文件“ C:\\用户\\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py”,第532行,打开时的响应= meth(req,response)文件“ C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py“,第642行,位于http_response“ http”中,请求,响应,代码,msg,hdrs)文件“ C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py”,第564行,错误结果= self._call_chain(* args)文件“ C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python \\ Python36 \\ lib \\ urllib \\ request”。 py”,第504行,在_call_chain中,结果= func(* args),文件“ C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py”,第756行,在http_error_302中返回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 笔(新的,超时=请求超时)文件“ C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py”,第532行,在打开的响应中= meth(req,响应)文件“ C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py”,第642行,位于http_response'http',请求,响应,代码,msg,hdrs) C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py“,第570行,错误返回self._call_chain(* args)文件” C:\\ Users \\ alext \\ AppData \\ _call_chain中的Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py“行504 = func(* args)文件” C:\\ Users \\ alext \\ AppData \\ Local \\ Programs \\ Python \\ Python36 \\ lib \\ urllib \\ request.py“,第650行,位于http_error_default中,引发HTTPError(req.full_url,code,msg,hdrs,fp)urllib.error.HTTPError:HTTP错误404:未找到

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. 您在城市之后缺少/,而预报中的AE。 It should be 它应该是

url = 'http://www.weather-forecast.com/locations/'+city+'/forecasts/latest'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 错误:urllib.error.HTTPError:HTTP 错误 404:未找到 - Python error: urllib.error.HTTPError: HTTP Error 404: Not Found urllib.error.HTTPError:HTTP 错误 404:未找到 - python - urllib.error.HTTPError: HTTP Error 404: Not found - python Python:urllib.error.HTTPError:HTTP 错误 404:未找到 - Python: urllib.error.HTTPError: HTTP Error 404: Not Found “ urllib.error.HTTPError:HTTP错误404:未找到” Python - “urllib.error.HTTPError: HTTP Error 404: Not Found” Python Python urllib.error.HTTPError:HTTP错误404:找不到 - Python urllib.error.HTTPError: HTTP Error 404: Not Found urllib2.HTTPError:HTTP错误404:找不到 - urllib2.HTTPError: HTTP Error 404: Not Found urllib.error.HTTPError:HTTP 错误 404:从 Metacritic 抓取数据时未找到 Python - urllib.error.HTTPError: HTTP Error 404: Not Found Python while scraping data from Metacritic urllib.error.HTTPError:HTTP 错误 404:未找到(雅虎财经) - urllib.error.HTTPError: HTTP Error 404: Not Found (Yahoo Finance) urllib.error.HTTPError: HTTP 错误 404: 未找到 yfinance 库 - urllib.error.HTTPError: HTTP Error 404: Not Found yfinance library 如何修复'urllib.error.HTTPError:HTTP错误404:找不到' - How to fix 'urllib.error.HTTPError: HTTP Error 404: Not Found'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM