Python Forum
Whats my python program's problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Whats my python program's problem (/thread-2384.html)

Pages: 1 2


Whats my python program's problem - arman - Mar-12-2017

İmage
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?


RE: Whats my python program's problem - metulburr - Mar-12-2017

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


RE: Whats my python program's problem - arman - Mar-12-2017

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)



RE: Whats my python program's problem - wavic - Mar-12-2017

When you paste a code copied from some IDE, use ctrl+shift+v


RE: Whats my python program's problem - arman - Mar-12-2017

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) 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

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

Error:
C:\Python27\python.exe C:/Users/arman/PycharmProjects/untitled1/asddf.py   File "C:/Users/arman/PycharmProjects/untitled1/asddf.py", line 8     download_web_image(http://www.reef2reef.com/data/ams/431/431079-8956905e1ef117b2e057a39686ede6a4.jpg)                            ^ SyntaxError: invalid syntax Process finished with exit code 1



RE: Whats my python program's problem - zivoni - Mar-12-2017

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")



RE: Whats my python program's problem - wavic - Mar-12-2017

Well, your function returns nothing. If that is your full code.


RE: Whats my python program's problem - zivoni - Mar-12-2017

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).


RE: Whats my python program's problem - wavic - Mar-12-2017

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



RE: Whats my python program's problem - arman - Mar-13-2017

(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 .
Error:
C:\Python27\python.exe C:/Users/arman/PycharmProjects/untitled1/asddf.py Traceback (most recent call last):   File "C:/Users/arman/PycharmProjects/untitled1/asddf.py", line 2, in <module>     import urllib.request ImportError: No module named request Process finished with exit code 1

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.