Python 3 urllib.request module download? / TS3 Python Plugin

+2 Hunter Shutt · January 26, 2016
Hey guys,

I just recently got interested in Python and wanted to know if there was a download for the urllib.request module. I've tryed downloading ones off the Project Interpreter but they don't work or don't even have that specific module installed.

I'm trying to make the webcrawler and since this was a year ago, it's probably updated and it's been removed or something. So is there another module I can use for this project?

import random
import urllib.request

def download_web_image(url):
    name = random.randrange(1, 1000)
    full_name = str(name) + '.jpg'
    urllib.request.urlretrieve(url, full_name)

download_web_image('https://www.thenewboston.com/photos/users/2/resized/23471ba4417d650505928a0b1f1fd8b1.jpg')

That's what I have in the project and it can't find urllib.request.

********

I also wanted to know if anyone knows how to install this in my TS3 server, and make my own plugins/scripts?

https://github.com/nikdoof/python-ts3

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
0 Sampan Verma · February 14, 2016
The original code is just fine. You should try using default Python Interpreter if you are using PyCharm or something. They sometimes mess things up. Try tweaking the file permissions. Or just download Python 3.4 again. There might be some problem in your previous download. All of these are just suggesstions.
import random
import urllib.request

def download_web_image(url):
name = random.randrange(1, 1000)
full_name = str(name) + '.jpg'
urllib.request.urlretrieve(url, full_name)

download_web_image('https://www.thenewboston.com/photos/users/2/resized/23471ba4417
d650505928a0b1f1fd8b1.jpg')


The tweaked around code had several mistakes in it. If you change import to from then you cannot just use urllib.request . Though I fixed it.
import random
from urllib.request import urlretrieve

def download_web_image(url):
name = random.randrange(1, 1000)
full_name = str(name) + '.jpg'
urlretrieve(url, full_name)

download_web_image('https://www.thenewboston.com/photos/users/2/resized/23471ba4417d650505928a0b1f1fd8b1.jpg')

You should have used 
from urllib.request import urlretrieve


Also further in the code, you should have used just
urlretrieve(...)
0 Sabeel Wani · February 13, 2016
import random
import urllib

def download_web_image():
url = "https://thenewboston.com/photos/users/70851/original/9a3fcea5398c7eb85ce5cc381574e33a.png"
name = random.randrange(1, 1000)
full_name = str(name) + '.jpg'
urllib.urlretrieve(url, full_name)
download_web_image()
0 Taiwo Kareem · February 4, 2016
For python2 it is 

import urllib2

import urllib

for python 3 do
from urllib.request import <something>
0 sfolje 0 · January 28, 2016
I tried with python 3.4.4 right now and the code that works is original:
import random
import urllib.request

def download_web_image(url):
name = random.randrange(1, 1000)
full_name = str(name) + '.jpg'
urllib.request.urlretrieve(url, full_name)

download_web_image('https://www.thenewboston.com/photos/users/2/resized/23471ba4417d650505928a0b1f1fd8b1.jpg')

Code that doesnt works for me ((  from urllib import urlretrieve
ImportError: cannot import name 'urlretrieve' )) :
import random
from urllib import urlretrieve

def download_web_image(url):
name = random.randrange(1, 1000)
full_name = str(name) + '.jpg'
urllib.request.urlretrieve(url, full_name)

download_web_image('https://www.thenewboston.com/photos/users/2/resized/23471ba4417d650505928a0b1f1fd8b1.jpg')

Something fishy is going on. Maybe because I have installed urllib3 module. What do you get if you run "pip list" ?
0 muha hasssan · January 27, 2016
bucky, come fix this
0 sfolje 0 · January 27, 2016
It seems like. Mine is 3.5.
0 Hunter Shutt · January 27, 2016
We might have different versions of Python, mine is 3.4.
0 sfolje 0 · January 26, 2016
Weird ... your original code works perfect for me.
0 Hunter Shutt · January 26, 2016
Ok, for everyone who DOESN'T know, this is how I fixed.


Instead of :
import urllib.request


It's this:
from urllib import urlretrieve
0 Hunter Shutt · January 26, 2016
Okay, so I guess no one knows.
  • 1
  • 2

Python

107,004 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator