python - Why does this code not download the file and the downloader can download it successfully -
the problem begins link
https://i1.pixiv.net/img-zip-ugoira/img/2017/04/05/00/24/41/62259492_ugoira600x600.zip
the file downloaded downloader complete.
and try use python download file
from urllib import request import sys request.urlretrieve('https://i1.pixiv.net/img-zip-ugoira/img/2017/04/05/00/24/41/62259492_ugoira600x600.zip', '123.zip') traceback (most recent call last): file "c:/users/ssshooter/pycharmprojects/first/111.py", line 3, in <module> request.urlretrieve('https://i1.pixiv.net/img-zip-ugoira/img/2017/04/05/00/24/41/62259492_ugoira600x600.zip', '123.zip') file "c:\users\ssshooter\appdata\local\programs\python\python36\lib\urllib\request.py", line 248, in urlretrieve contextlib.closing(urlopen(url, data)) fp: file "c:\users\ssshooter\appdata\local\programs\python\python36\lib\urllib\request.py", line 223, in urlopen return opener.open(url, data, timeout) file "c:\users\ssshooter\appdata\local\programs\python\python36\lib\urllib\request.py", line 532, in open response = meth(req, response) file "c:\users\ssshooter\appdata\local\programs\python\python36\lib\urllib\request.py", line 642, in http_response 'http', request, response, code, msg, hdrs) file "c:\users\ssshooter\appdata\local\programs\python\python36\lib\urllib\request.py", line 570, in error return self._call_chain(*args) file "c:\users\ssshooter\appdata\local\programs\python\python36\lib\urllib\request.py", line 504, in _call_chain result = func(*args) file "c:\users\ssshooter\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 403: forbidden
it doesn't work.
the differences are:
- you're using different ssl information: you're browser has built-in set of certificate authorities. python uses set comes os. differ & if site you're accessing uses 1 know browser not known python, python throw exception.
- you're accessing using different user-agents. browser telling server it's chrome or ie or whatever. python telling server it's python. whatever reason, server may decide doesn't , return forbidden.
- the server may working harder think: while appears request simple file, you're requesting resource. may (though unlikely in case) resource you're requesting results in multiple interactions between server , browser -- cookies, javascript, etc -- executed in browser, returned server & delivers file. python request not doing of that.
- your browser (may) have existing state python not. can access file using browser, works because you've accessed other resources on site, or logged in, or whatever. browser communicating information (perhaps session_id via cookie?) server recognizes. python code states no previous state, server forbids that.
which in case? you'll need investigate. can wget or curl work? debug browser's access: headers being sent, receiving in reply?
Comments
Post a Comment