I am beginner python prorammer. With 2.7.2, Windows 7, built-in interpreter, and three libraries. I am trying to do this, with error. I appreciate any help?
import os
import urllib
import socket
DISNEY_URL = 'http://www.sec.gov/Archives/edgar/data/1001039/000119312511321340/dis-20111001.xml'
#Neither of these seem to work when opening with urllib.urlopen becaue of the error:
#I/O error(socket error): [Errno 11004] getaddrinfo failed
DISNEY_LOCAL = 'file://C:/Users/Nate/Desktop/Education/python_education/xbrlnexusfiles/xbrlfiles/dis-20111001.xml'
DISNEY_LOCAL_NONE = 'file://C:/Users/Nate/Desktop/Education/python_education/xbrlnexusfiles/xbrlfiles/dis.txt'
class SECFilingPackage(object):
def __init__ (self, SEC_URL):
URLFilePath, URLFileExt = os.path.splitext(SEC_URL)
try:
urllib.urlopen(SEC_URL)
except IOError as (errno, strerror):
print "I/O error({0}): {1}".format(errno, strerror)
#This error throws, see it copied above;
DisneyPackage = SECFilingPackage(DISNEY_LOCAL_NONE)
I get this error: I/O error(socket error):
[Errno 11004] getaddrinfo failed
Yes the text file exists at that location. The contents of the text file is "Nothing"
The stack trace says the last call was line 516 in open_ftp
C:/Python27/Lib/urllib.py
:
host = socket.gethostbyname(host)
IOError: [Errno socket error] [Errno 11004] getaddrinfo failed
I could open URLs fine, so I don't think it's a proxy/firewall issue (nor do I understand that really)
And I don't understand what newlines or ENDs might have to do with it.
I believe it should work because of the urllib reference:
If the URL does not have a scheme identifier, or if it has file: as its scheme identifier, this opens a local file (without universal newlines); otherwise it opens a socket to a server somewhere on the network.
(I think this just means someone who expects universal newlines already converted there, would be disappointed.
Note I also dispute the part about "if it does not have a scheme identifier", because if I don't precede the strings with file://
I get
IOError: [Errno url error] unknown url type: 'c')
I want to "learn to fish" so to speak, can anyone tell me is there a way I could debug into the urllib.py
to at least understand these values? Can I do it with eclipse? It always seems to force me into a project.
Instead of file://<filename>
, use file:///<filename
(note the extra slash).
Also, please note that urllib.urlopen
has been deprecated, you should use urllib2.urlopen
instead.