Forums

Getting image from an url results in nothing

import urllib import cv2 import numpy as np

def index():

    url = "a url"

    url_response = urllib.urlopen(url)

    img_array = np.array(bytearray(url_response.read()), dtype=np.uint8)

    img = cv2.imdecode(img_array, -1)

    cv2.imwrite("=========test.jpeg", img)

    cv2.waitKey()

    return 1

After running this code, my "=========test.jpeg" is a blank file. What's wrong with my code?

If you are trying to pull in data from an external site, make sure that it is on our whitelist. Free users are limited to only access our whitelist over http/https, and we only add websites with api's that are clearly documented to the whitelist. If you believe that this is the case, please provide us with a link to the documentation.