Python Forum
Whats my python program's problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Whats my python program's problem
#1
İ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?
Reply
#2
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:
Reply
#3
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)
Reply
#4
When you paste a code copied from some IDE, use ctrl+shift+v
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
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
Reply
#6
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")
Reply
#7
Well, your function returns nothing. If that is your full code.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#8
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).
Reply
#9
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#10
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Whats wrong with the elif? inunanimous93 3 2,478 Nov-30-2020, 03:58 AM
Last Post: deanhystad
  Whats Wrong!? rjay81 3 2,266 May-13-2020, 08:02 PM
Last Post: rjay81
  Can u see this code and tell whats wrong with it? AhmadKamal 14 5,341 Apr-29-2020, 11:09 AM
Last Post: jefsummers
  Whats a good design/approach? hshivaraj 1 1,785 Sep-16-2019, 01:44 AM
Last Post: snippsat
  Problem: Once I cancel the process my program will start working! Hadad 0 1,659 Jul-24-2019, 04:09 PM
Last Post: Hadad
  elevator simulator...whats the wrong at this code? tasos710 5 5,928 Jun-11-2019, 01:38 AM
Last Post: micseydel
  Program Problem (2) ChrisG 2 2,400 May-25-2019, 05:11 PM
Last Post: ChrisG
  Program Problem ChrisG 2 1,978 May-25-2019, 11:41 AM
Last Post: ChrisG
  whats the difference between sys.exit() and break? mitmit293 1 4,124 Jan-27-2019, 09:46 PM
Last Post: ichabod801
  Whats wrong with this code? student1 1 2,406 May-18-2018, 04:19 PM
Last Post: skorpius_

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020