I was watching the Buckys tutorial about how to download the image from internet and i copied all he said but my program did not work.
Im new to this forum.How can i send an image from my pc?
Whats my python program's problem
|
I was watching the Buckys tutorial about how to download the image from internet and i copied all he said but my program did not work. Im new to this forum.How can i send an image from my pc?
1) What is the code you are using? Post in python code tags here on the forum
2) How big is the file you are downloading? 3) What is the link to the youtube tutorial you are using? 4) When you say "it did not work" What happened? What was the error? 5) Do you need to login to see the file, or can the public access it? Quote:How can i send an image from my pc? 6) send an image to where? 7) Im switching this to general coding because you should have put your code you are using
Recommended Tutorials:
import random import urllib.request def download_web_image(url): name=random.randrange(1,1000) fullname=str(name)+".jpg" urllib.request.urlretrieve(url,fullname) download_web_image(http://www.reef2reef.com/data/ams/431/431079-8956905e1ef117b2e057a39686ede6a4.jpg)
Mar-12-2017, 09:29 PM
When you paste a code copied from some IDE, use ctrl+shift+v
import random import urllib.request def download_web_image(url): name=random.randrange(1,1000) fullname=str(name)+".jpg" urllib.request.urlretrieve(url,fullname) download_web_image(http://www.reef2reef.com/data/ams/431/431079-8956905e1ef117b2e057a39686ede6a4.jpg) (Mar-12-2017, 09:21 PM)metulburr Wrote: 1) What is the code you are using? Post in python code tags here on the forum 2)i choosed a random image from a site. 3)http://www.aparat.com/v/ZyPFU, this is the link but its not you tube. 4)SyntaxError: invalid syntax this was the error 5)im logged in the site but everyone can access it 6)To the thread i started Thank you for helping me.Im a beginner and it takes a bit to learn evrything
url of image passed to your download_web_image function should be enclosed in quotes:
import random import urllib.request def download_web_image(url): name=random.randrange(1,1000) fullname=str(name)+".jpg" urllib.request.urlretrieve(url,fullname) download_web_image("http://www.reef2reef.com/data/ams/431/431079-8956905e1ef117b2e057a39686ede6a4.jpg")
Mar-12-2017, 09:48 PM
Well, your function returns nothing. If that is your full code.
urllib.request.urlretrieve should save downloaded image to a filename starting with randomly generated number...
And I think that python2 does not have urllib.request and uses just urllib.urlretrieve ... (i did not see the error code before my previous post).
Mar-12-2017, 10:42 PM
Why not a sequence of numbers but a random number for a file name? If this is used for more than one downloaded file name it is possible to rewrite an existing file.
Using uuid is more suitable in this case. It's unlikely to get two equal numbers. >>> import uuid >>> file_id = uuid.uuid4() >>> file_id UUID('08830c82-48a7-453d-9a83-cd5fca522712') >>> name = file_id.int >>> name 11314268565808898375662089066352092946 (Mar-12-2017, 09:44 PM)zivoni Wrote: url of image passed to your download_web_image function should be enclosed in quotes:oh yes that was the problem. But this is another error .
I use pycharm and i added the library request but it didnt work.Is adding a library named "urllib.request"enough? (Mar-12-2017, 09:48 PM)wavic Wrote: Well, your function returns nothing. If that is your full code.It has to save a simple pictur.Im just learning web programming. |
|