1

I am on Windows 8, installed Anaconda Python 2.7.11. here's my python code:

import urllib2
url = "http://real-chart.finance.yahoo.com/table.csv?s=GOOG&ignore=.csv"
response = urllib2.urlopen(url)
data = response.read()
read = csv.DictReader(data)

I just found this code somewhere else and copied it (and replaced it with my own url).

And I am getting this error trace:

Traceback (most recent call last):
  File "01_get_traindata.py", line 25, in <module>
    response = urllib2.urlopen(url)
  File "C:\Users\Tin Tran\Anaconda2\lib\urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\Tin Tran\Anaconda2\lib\urllib2.py", line 431, in open
    response = self._open(req, data)
  File "C:\Users\Tin Tran\Anaconda2\lib\urllib2.py", line 449, in _open
    '_open', req)
  File "C:\Users\Tin Tran\Anaconda2\lib\urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "C:\Users\Tin Tran\Anaconda2\lib\urllib2.py", line 1227, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "C:\Users\Tin Tran\Anaconda2\lib\urllib2.py", line 1197, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10013] An attempt was made to access a s
ocket in a way forbidden by its access permissions>

I read somewhere else that it might have to do something firewall so I have disabled my firewall and it's still happening.

Things i have tried: setting the python.exe to run as administrator (I got "Access denied." in command window after being prompted to run as administrator) already allowed python.exe in my firewall (still doesn't work). Even turned off firewall completely (still doesn't work). I checked and my account is already admin as well.

UPDATE: solved after i restarted computer. I do still have my firewall turned off and allow python.exe through my firewall. Maybe a restart was needed. Strange.

Tin Tran
  • 5,995
  • 2
  • 15
  • 32

2 Answers2

0

Not sure what you are trying to do but try :

import urllib
urllib.urlretrieve ("http://real-chart.finance.yahoo.com/table.csv?s=GOOG&ignore=.csv", "csv.csv")

that works and save the file locally.

Then try to work with your file on your computer ?

Blimeys
  • 176
  • 8
  • I found this code somewhere else too and the same error occurs. UPDATE : Weird I copied your code and it works now i wonder what i did differently this time – Tin Tran Mar 13 '16 at 18:44
  • Well at last it works ! I'm glad you got that sorted. – Blimeys Mar 14 '16 at 10:29
-1

Your code works for me on Win10, CPython. Problem might happen because you run script in unprivileged mode. See:

https://stackoverflow.com/a/2779304/1113207

So you can try to run python interpreter as administrator or/and disable UAC.

Other possible reason is that local firewall prevented the connection:

https://stackoverflow.com/a/6806143/1113207

Try to disable it to see if it's problem.

Community
  • 1
  • 1
Mikhail Gerasimov
  • 27,590
  • 10
  • 86
  • 127
  • disabled firewall and it's still happening...with the first link there i am not sure what the solution is exactly like how do i give admin priviledges to my python.exe? – Tin Tran Mar 13 '16 at 16:59
  • @TinTran, I would try following 1) run interpreter (python.exe) as administrator: http://www.cnet.com/how-to/always-run-a-program-in-administrator-mode-in-windows-10/ 2) Disable UAC: https://www.articulate.com/support/storyline/how-to-turn-user-account-control-onoff-in-windows-8 – Mikhail Gerasimov Mar 13 '16 at 17:06
  • @TinTran 3) Try to disable your antivirus too :) – Mikhail Gerasimov Mar 13 '16 at 17:11
  • let's say i choose to right click python.exe and run as administrator how do i make it run a .py file in while running python...sorry I am only used to running "python.exe myfile.py" kind of execution – Tin Tran Mar 13 '16 at 17:12
  • @TinTran I don't know that too. How about to set checkbox "Run as administrator" in interpreter file's properties? (see link on cnet.com above) In that case interpreter would be running as administrator every time. – Mikhail Gerasimov Mar 13 '16 at 17:20
  • I set the python.exe to run as administrator..now when i run i get prompted to run as admin i click ok. and i get "Access denied." in the command window as output. I also noticed that my account is already and an Admin account type. Sorry this error is really frustrating as i have not a clue how to overcome it. – Tin Tran Mar 13 '16 at 18:38