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)

download_from_web("https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xaf1/v/t1.0-9/10004010_803742099692416_9063316911684720227_n.jpg?oh=9c810cfa5ddcc7fd8b6b03f5f3e691df&oe=5526F529&__gda__=1428584856_0590416ce907a25715f363fca411b7e8")

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
    self.endheaders(body)
  File "C:\Python34\lib\http\client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "C:\Python34\lib\http\client.py", line 924, in _send_output
    self.send(msg)
  File "C:\Python34\lib\http\client.py", line 859, in send
    self.connect()
  File "C:\Python34\lib\http\client.py", line 1221, in connect
    super().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
    sock.connect(sa)
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>
    download_from_web("https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xaf1/v/t1.0-9/10004010_803742099692416_9063316911684720227_n.jpg?oh=9c810cfa5ddcc7fd8b6b03f5f3e691df&oe=5526F529&__gda__=1428584856_0590416ce907a25715f363fca411b7e8")
  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

Replies

Oldest  Newest  Rating
0 Dhawal S · February 14, 2015
thnkzz for solution frnd ##even im facing the same prOblem
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
yeah
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
  • 1

Python

107,123 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator