我是初学者 python prorammer。带有 2.7.2、Windows 7、内置解释器和三个库。我正在尝试这样做,但有错误。我很感激任何帮助?
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/O 错误(套接字错误):
[Errno 11004] 获取地址信息失败
是的,文本文件存在于该位置。文本文件的内容是“Nothing”
堆栈跟踪显示最后一次调用是第 516 行open_ftp
C:/Python27/Lib/urllib.py
:
host = socket.gethostbyname(host)
IOError: [Errno socket error] [Errno 11004] getaddrinfo failed
我可以很好地打开 URL,所以我认为这不是代理/防火墙问题(我也不明白)
而且我不明白换行符或 END可能与它有什么关系。
如果 URL 没有方案标识符,或者如果它有 file: 作为其方案标识符,这将打开一个本地文件(没有通用换行符);否则它会打开一个连接到网络上某处服务器的套接字。
(我认为这只是意味着希望通用换行符已经在那里转换的人会感到失望。
注意我也对“如果它没有方案标识符”的部分提出异议,因为如果我没有在字符串前面加上file://
我得到
IOError:[Errno url 错误] 未知 url 类型:'c')
可以这么说,我想“学会钓鱼”,谁能告诉我有没有办法调试到urllib.py
至少理解这些值?我可以用eclipse来做吗?它似乎总是迫使我进入一个项目。