How do I convert urllib parameters to urllib3? [closed]

asked 2016-10-15 10:24:04 -0600

Hi everyone,

This code makes the URLs of the images contained in the link, be resized and saved in a folder. The code is not mine, but I intend to use it as the basis for my project. Link

Here's the code:

import urllib.request
import cv2
import numpy as np
import os

def store_raw_images():
    neg_images_link = '//image-net.org/api/text/imagenet.synset.geturls?wnid=n00523513'
    neg_image_urls = urllib.request.urlopen(neg_images_link).read().decode()
    pic_num = 1

    if not os.path.exists('neg'):
        os.makedirs('neg')

    for i in neg_image_urls.split('\n'):
        try:
            print(i)
            urllib.request.urlretrieve(i, "neg/" + str(pic_num) + ".jpg")
            img = cv2.imread("neg/" + str(pic_num) + ".jpg", cv2.IMREAD_GRAYSCALE)
            # should be larger than samples / pos pic (so we can place our image on it)
            resized_image = cv2.resize(img, (100, 100))
            cv2.imwrite("neg/" + str(pic_num) + ".jpg", resized_image)
            pic_num += 1

        except Exception as e:
            print(str(e))
store_raw_images()

Whenever I run the code, appears this message:

import urllib.request ImportError: No module named request

I have currently installed urllib3 module and I would like to know how to run this code converting urllib parameters to urllib3.

I would like your help to solve this case.

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2016-10-15 10:38:08.651407

Comments

unfortunately, your basic problem is not at all an opencv one.

berak gravatar imageberak ( 2016-10-15 10:37:06 -0600 )edit