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


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

The module is requests with 's'.
My bad.
Which Python version do you use?


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

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


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

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?


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

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