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
#11
The module is requests with 's'.
My bad.
Which Python version do you use?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#12
As I wrote earlier, python2.7 does not have urllib.request library. You can either use python3 with your original code, or change your code to either use requests or urllib.

This code should work with python 2.7 - uses just urllib

import random
import urllib
def download_web_image(url):
    name=random.randrange(1,1000)
    fullname=str(name)+".jpg"
    urllib.urlretrieve(url,fullname)
  
download_web_image("http://www.reef2reef.com/data/ams/431/431079-8956905e1ef117b2e057a39686ede6a4.jpg")
EDIT: If you are just starting with python and following tutorial with python3 examples, you should install and use python 3.x instead of python 2.7
Reply
#13
I got it.I just searched throgh the external libray and saw the module name is changed to urllib and its not urllib.request.

(Mar-13-2017, 01:55 PM)zivoni Wrote: As I wrote earlier, python2.7 does not have urllib.request library. You can either use python3 with your original code, or change your code to either use requests or urllib. This code should work with python 2.7 - uses just urllib
 import random import urllib def download_web_image(url):     name=random.randrange(1,1000)     fullname=str(name)+".jpg"     urllib.urlretrieve(url,fullname)   download_web_image("http://www.reef2reef.com/data/ams/431/431079-8956905e1ef117b2e057a39686ede6a4.jpg") 
EDIT: If you are just starting with python and following tutorial with python3 examples, you should install and use python 3.x instead of python 2.7
yes that was my problem.

(Mar-13-2017, 01:48 PM)wavic Wrote: The module is requests with 's'. My bad. Which Python version do you use?
I use pycharm2016.3.2

One more thing,i love programming and i just programmed c++ about two years ago and im interested in micro controllers such as ARM,AVR,...
I get started with python when i wanted to get familiar to raspberry boards.
Is there any books or videos that can help me learning about python more and more?
Reply
#14
in python3.x its
urllib.request.urlretrieve() 

in python2.x its
urllib.urlretrieve() 


type in request here to search
https://python-forum.io/pages/porting.php

urllib.request is python3.x standard libs while requests is a 3rd party module

EDIT:
 a little late again, didnt see the second thread page before posting :)
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Whats wrong with the elif? inunanimous93 3 2,403 Nov-30-2020, 03:58 AM
Last Post: deanhystad
  Whats Wrong!? rjay81 3 2,214 May-13-2020, 08:02 PM
Last Post: rjay81
  Can u see this code and tell whats wrong with it? AhmadKamal 14 5,181 Apr-29-2020, 11:09 AM
Last Post: jefsummers
  Whats a good design/approach? hshivaraj 1 1,739 Sep-16-2019, 01:44 AM
Last Post: snippsat
  Problem: Once I cancel the process my program will start working! Hadad 0 1,630 Jul-24-2019, 04:09 PM
Last Post: Hadad
  elevator simulator...whats the wrong at this code? tasos710 5 5,835 Jun-11-2019, 01:38 AM
Last Post: micseydel
  Program Problem (2) ChrisG 2 2,358 May-25-2019, 05:11 PM
Last Post: ChrisG
  Program Problem ChrisG 2 1,937 May-25-2019, 11:41 AM
Last Post: ChrisG
  whats the difference between sys.exit() and break? mitmit293 1 4,081 Jan-27-2019, 09:46 PM
Last Post: ichabod801
  Whats wrong with this code? student1 1 2,371 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