Why its not working?? #tutorial 22

+2 Ray Haq · January 20, 2015

import random
import urllib.request

def download_from_web(url):
    name = random.randrange(100, 1000)
    full_name = str(name) + ".jpg"
    urllib.request.urlretrieve(url, full_name)


it not downloading anything but showing some errors!
i am not understanding why
plz some one help me

C:\Python34\python.exe "C:/Users/Ray Haq/PycharmProjects/Youtube/main.py"
Traceback (most recent call last):
  File "C:\Python34\lib\urllib\request.py", line 1174, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "C:\Python34\lib\http\client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "C:\Python34\lib\http\client.py", line 1128, in _send_request
  File "C:\Python34\lib\http\client.py", line 1086, in endheaders
  File "C:\Python34\lib\http\client.py", line 924, in _send_output
  File "C:\Python34\lib\http\client.py", line 859, in send
  File "C:\Python34\lib\http\client.py", line 1221, in connect
  File "C:\Python34\lib\http\client.py", line 836, in connect
    self.timeout, self.source_address)
  File "C:\Python34\lib\socket.py", line 509, in create_connection
    raise err
  File "C:\Python34\lib\socket.py", line 500, in create_connection
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Ray Haq/PycharmProjects/Youtube/main.py", line 9, in <module>
  File "C:/Users/Ray Haq/PycharmProjects/Youtube/main.py", line 7, in download_from_web
    urllib.request.urlretrieve(url, full_name)
  File "C:\Python34\lib\urllib\request.py", line 178, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "C:\Python34\lib\urllib\request.py", line 153, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python34\lib\urllib\request.py", line 455, in open
    response = self._open(req, data)
  File "C:\Python34\lib\urllib\request.py", line 473, in _open
    '_open', req)
  File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain
    result = func(*args)
  File "C:\Python34\lib\urllib\request.py", line 1217, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "C:\Python34\lib\urllib\request.py", line 1176, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions>

Process finished with exit code 1

btw, some other software are not  connecting on network either
like google earth, windows installer

i dont understand what is the problem
will i have to install windows again?
please help

Post a Reply


Oldest  Newest  Rating
0 Vuk Skobalj · January 21, 2015
l just copied your code to PyCharm and he downloaded that picture Bangladesh successfully,works for me
0 Ray Haq · January 22, 2015
i just found out the problem

the avg antivirus was interfering with network connection of my pc
it now works correctly

btw, thanks for taking some time to comment
0 Dhawal S · February 14, 2015
thnkzz for solution frnd ##even im facing the same prOblem
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator