May-28-2019, 05:26 AM
hi there
I was trying to get address by using API, but I got HTTP Error. Does it mean URL I code didn't make sense or only I couldn't get data from the URL?
My code is here.
And the Error is this
I was trying to get address by using API, but I got HTTP Error. Does it mean URL I code didn't make sense or only I couldn't get data from the URL?
My code is here.
import urllib.request
import urllib.parse
API = "https://api.aoikujira.com/zip/xml.get.php"
#パラメータをURLエンコードする
values = {
'fmt' : 'xml',
'zn' : '1740064'
}
params = urllib.parse.urlencode(values)
#リクエスト用のURLを作成
url = API + "?" + params
print("url = ", url)
#ダウンロード
data = urllib.request.urlopen(url).read()
text = data.decode("utf-8")
print(text) And the Error is this
Error:url = https://api.aoikujira.com/zip/xml.get.php?fmt=xml&zn=1740064
Traceback (most recent call last):
File "download-zip.py", line 18, in <module>
data = urllib.request.urlopen(url).read()
File "C:\Users\…\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\…\Python\Python36-32\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "C:\Users\…\Python\Python36-32\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\…\Python\Python36-32\lib\urllib\request.py", line 570, in error
return self._call_chain(*args)
File "C:\Users\…\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\…\Python\Python36-32\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 FoundHow can I solve it?
