2012-01-29 145 views
2

我是初学者python prorammer。使用2.7.2,Windows 7,内置解释器和三个库。我试图做到这一点,错误。我感谢任何帮助?IOError:[Errno socket error] [Errno 11004] getaddrinfo失败

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] getaddrinfo failed

是文本文件存在于该位置。该文本文件的内容是“无”

堆栈跟踪说,最后一次通话是线516 open_ftpC:/Python27/Lib/urllib.py

host = socket.gethostbyname(host) 
IOError: [Errno socket error] [Errno 11004] getaddrinfo failed 

我可以打开网址的很好,所以我不认为这是一个proxy/firewall issue (我也不明白)

而我不明白newlines or ENDs可能与它有什么关系。

我相信它应该是因为工作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.

(我认为这只是意味着有人谁希望通用换行已经转换那里,会很失望。

注意我也争对部分“如果没有一个方案标识符”,因为如果我不file://先于字符串,我得到

IOError: [Errno url error] unknown url type: 'c')

我想“学会钓鱼”可以这么说,谁能告诉我有没有一种方法可以调试到urllib.py以至少了解这些值?我可以用日食来做到吗?它似乎总是迫使我成为一个项目。

+1

http://stackoverflow.com/questions/5022945/urllib2-urlerror-urlopen-error-errno-11004-getaddrinfo-failed – jdi 2012-01-29 17:29:38

回答

2

而不是file://<filename>,使用file:///<filename(注意额外的斜线)。

此外,请注意urllib.urlopen已被弃用,您应该使用urllib2.urlopen来代替。

+2

他实际上应该使用Python-请求 – rapadura 2012-01-29 17:34:09

+0

谢谢jcollado。谢谢,安东尼奥。 Python请求看起来不错... http://docs.python-requests.org/en/latest/index.html – 2012-09-12 12:28:07

相关问题