Python Programming Tutorial – 22 – Download an Image from the Web

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

49 responses to “Python Programming Tutorial – 22 – Download an Image from the Web”

  1. davortech Avatar

    Nice, but isn’t that a bit complicated for beginners? The easiest way in my opinion is this: https://pastebin.com/i5jJHTP9

  2. Fakrudeen Ali T Avatar

    I got the following error. Can anyone please help me ?
    Traceback (most recent call last):
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32liburllibrequest.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libhttpclient.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libhttpclient.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libhttpclient.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libhttpclient.py", line 1026, in _send_output
    self.send(msg)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libhttpclient.py", line 964, in send
    self.connect()
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libhttpclient.py", line 1400, in connect
    server_hostname=server_hostname)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libssl.py", line 407, in wrap_socket
    _context=self, _session=session)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libssl.py", line 814, in _init_
    self.do_handshake()
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32libssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
    ssl.SSLError: [SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:777)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "atom.py", line 6, in <module>
    urllib.request.urlretrieve(url , name)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32liburllibrequest.py", line 248, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32liburllibrequest.py", line 223, in urlopen
    return opener.open(url, data, timeout)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32liburllibrequest.py", line 526, in open
    response = self._open(req, data)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32liburllibrequest.py", line 544, in _open
    '_open', req)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32liburllibrequest.py", line 504, in _call_chain
    result = func(*args)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32liburllibrequest.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
    File "C:UsersalitAppDataLocalProgramsPythonPython36-32liburllibrequest.py", line 1320, in do_open
    raise URLError(err)
    urllib.error.URLError: <urlopen error [SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:777)>

  3. M. Shakhawat Hussain Avatar

    import random
    import urllib.request

    def download_web_image(url):
    name = random.randrange(1, 1000)
    full_name = str(name) + ".jpg"
    urllib.request.urlretrieve(url, full_name)

    download_web_image("https://en.wikipedia.org/wiki/File:Hemerocallis_lilioasphodelus_flower.jpg&quot😉

    the program executed successfully, but when im opening the file, it showing " Image not loaded, try it open externally to fix format problem". how can i solve this problem?

  4. Satyam Somadutta Avatar

    getting error while installing the packages. It is happening for any package I am trying to install.. 🙁
    ANY ONE can HELP ??

  5. Taeyoongi Avatar

    or you can just righclick the photo and saveas

  6. Roberto Pierdomenico Avatar

    sorry guys but is a project interpreter actually is? thansk

  7. Java-Tutorial Avatar

    Very nice thanks a lot …

  8. Paweł Brysch Avatar

    x=5
    str(5)
    //
    str() działa na CAŁE pliki

  9. Paweł Brysch Avatar

    File->Setting->Project:nazwa_projektu->File Interpreter – pobieranie (i szukanie) modułów

  10. Kadircan ÖKSÜZOĞLU Avatar

    Bucky, you are a walking wikipedia !! Thank you for everything you teached to us. Grand master !!

  11. rajesh reddy Avatar

    thanks bucky loved your videos and learnt a lot…
    keep up the good work.

  12. Pieter Avatar

    innernet or internet?

  13. mogalana vats Avatar

    Does anyone have the url of buckyrooms.org. Please send the link

  14. Gordon Aiken Avatar

    I'm having problems downloading images from https sources but http seems to work fine, I'd recommend giving that a go if you are hitting problems, at least you can see the code work that way. If anyone can suggest a workaround for https hosted images then that would be great.

  15. misty thelion Avatar

    its 2018 and i'm not sure why its not working for me. im getting " AttributeError: module 'urllib' has no attribute 'urlretrieve' "

  16. siva prasad Avatar

    Hi Bucky, your tutorials are really cool. I am having a query, I am able to access the web page content and able to download the same into XXXXX.jpg. I could see the file created in the same folder where my source code residing. But for some reasons, I don't see the *.jpg file in my workspace. FYI, I am using eclipse for my practice. I have restarted the eclipse, remapped the workspace but no luck.

  17. Yahye Jama Avatar

    I think we can skip the random part. like this — and it works

    import urllib.request

    def picture(url):
    full_name = str('yahye') + ".jpg"
    urllib.request.urlretrieve(url, full_name)
    picture("https://cdn.theatlantic.com/assets/media/img/mt/2017/01/GettyImages_476064417-1/lead_large.jpg?1485207556&quot😉

  18. Mehmet Ece Avatar

    For anyone using 2017 Pycharm, first things first, make sure you go to Preferences>Project Structure then right click your main folder and set it to blue (sources).

    after that, try entering in this code and running it.

    import random
    import urllib

    def download_web_image(url):
    name = random.randrange(1, 1000)
    full_name = str(name) + ".jpg"
    urllib.urlretrieve(url, full_name)
    download_web_image("https://i.imgur.com/qgFDcNk.jpg&quot😉

    It works for me.

  19. Sairishab Hastantaram Avatar

    i am getting "image not loaded" "try to open it externallyto fix the format problem" this error can anyone plz help

  20. Rajat Gupta Avatar

    Got some kind of HTTP Error. How do i resolve it?

    raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 403: Forbidden

  21. hi hi shona baby Avatar

    Why we use random range ??

  22. vishal anand Avatar

    after execution the downloaded image is not opening and shows some stuff like "try to open it externally to fix format problem" .while opening it externally in photos also it's not opening

  23. Karsten Wake Avatar

    Issue Solved!
    Program ran with no issue and no error but no image file showed up in directory.
    It appeared that it wasn't working but it really was just not refreshing automatically the directory when running program. I use eclipse IDE btw. I had to right-click my directory directly and click refresh and all my imported files popped up.
    Others are having issue of no image showing up, so maybe this will help.

  24. Devesh Kumar Avatar

    my code is perfectly running but the image is not opening? any suggestions

  25. sai kiran Avatar

    What is the part that ranging from 55sec to 2.15 min explains about .anyone please help me

  26. sai kiran Avatar

    Are these random and urllib.request are preinstalled modules

  27. sai kiran Avatar

    Why we had imported random and urllib . although we had not called them

  28. Avinash Kumar Avatar

    Any idea how the resolution of the downloaded images can be changed. Looks small and blurry at the moment 🙂
    Also wanted to know if we can download multiple images from a single page. Example a tumblr page. Is it one of ur future tutorial?

  29. Smidgen Avatar

    im having an issue i know the video is 3 years old but the URL doesnt download and it coming up with an error saying something about the urlLib

  30. Kushagra Oberoi Avatar

    Screen Shot 2017-12-03 at 4.19.08 pm

  31. Yaron Shaul Avatar

    Do I have to install VS C++ in order to add packages in Pycharm??

  32. markobe08 Avatar

    I get this message "Standard library module invoked user code during import; breakpoints disabled for invoked code". what that means??

  33. DrLoud RS Avatar

    I'm having an issue in that no image appears downloaded. The code runs without hangups nor errors, but I don't get any image downloaded. Have been pulling my hair out. The code is as follows:

    import random
    import urllib.request

    def download_web_image(url):
    name = random.randrange(1, 1000)
    full_name = str(name) + ".jpg"
    urllib.request.urlretrieve(url, full_name)

    download_web_image("https://www.thenewboston.com/photos/users/5041/resized/2f848a75dae149f48500c50dbfbb56aa.jpg&quot😉

    Output is:

    C:Python34python.exe C:/Users/*****/PycharmProjects/Tuna/main.py

    Process finished with exit code 0

    With no image downloaded.

    Could anyone assist me in finding out what is happening? I'm hesitant in proceeding in the tutorial series until I feel that I understand the concepts

  34. Balu Balaguru Avatar

    Great tutoring with a sense of humor…thanks

  35. Alex Hung Avatar

    So weird that without using those import commands, I can still use the following functions smoothly. Why is this? I am using anaconda BTW.

  36. Neddih Lous Avatar

    nice tutorials

  37. Venkatesh Mundada Avatar

    How to download a FB picture, pic is getting downloaded, but invalid pic

  38. Panda 08 Avatar

    So everytime i go to the project interpreter the + sign is always greyed out and i can't click on it. Any help how to download a package?

  39. MAHESHGOUDA PATIL Avatar

    Can we change the path for the image to be downloaded . . .?

  40. Viraj Singh Avatar

    I feel enchanted to watch you videos.

  41. Queen Cleopatra Avatar

    ok guys, if you're using a Mac or python 3.6 and your program is still not working. Here's how I did it and it works! yay! =D, thanks to another video from him about downloading csv file from the internet.

    import random 
    from urllib import request 

    def download_web_image(url):
        name = random.randrange(1, 1000)    
        full_name = str(name) + '.jpg' 
        request.urlretrieve(url, full_name)
    download_web_image('http://lorempixel.com/400/200&#39😉

  42. Queen Cleopatra Avatar

    How do you know the functions of a module? Is there a list where one can see the functions that can be used with a given module?

  43. Sriram gnv Avatar

    my available packages in project interpreter is empty.
    what can i do now?

  44. rohit chakrabarti Avatar

    to save in separate folder :
    import random
    import urllib.request

    def download(url):
    img=random.randrange(1,1000)
    full=str(img)+".jpg"
    location='uploads/'+full;
    urllib.request.urlretrieve(url, location)
    download("http://s3.amazonaws.com/libapps/accounts/20425/images/fox_badger.jpg&quot😉

  45. Sean Rebeiro Avatar

    I'm getting an error on line 6 at "str" why? pls help

  46. Silvia wahballa Avatar

    how can I do the same using visual studio not pycharm?

Leave a Reply

Your email address will not be published. Required fields are marked *