IOError:[Errno socket error][Errno 11004]getaddrinfo失败

2024-05-15 14:14:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python prorammer的初学者。有2.7.2、Windows7、内置解释器和三个库。我试图这样做,但有错误。我很感激你的帮助?

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

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

堆栈跟踪显示最后一个调用是open_ftpC:/Python27/Lib/urllib.py中的516行:

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

我可以很好地打开url,所以我不认为它是一个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.

(我认为这仅仅意味着那些期待通用新线路已经在那里转换的人会失望。

注意,我还对“如果它没有scheme标识符”这一部分有争议,因为如果我没有在字符串前面加上file://,我将得到

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

我想“学会钓鱼”可以这么说,有没有人能告诉我,有没有一种方法可以调试到urllib.py中,以至少理解这些值?我可以用eclipse吗?它似乎总是强迫我去做一个项目。


Tags: theimporturllocal错误errorsocketsec
1条回答
网友
1楼 · 发布于 2024-05-15 14:14:12

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

另外,请注意urllib.urlopen已被弃用,您应该改用urllib2.urlopen

相关问题 更多 >