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.

enter image description here

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -