2013-08-22 5 views
0

다음 코드는 프록시 외부에서 프로그램을 실행할 때 실행됩니다. Windows 7 운영 체제를 사용하여 작업중인 프록시에서이 프로그램을 실행하면 명령 프롬프트에서 "[Errno 11004]"또는 Cygwin에서 "[Errno 8]"을 얻습니다.파이썬 충돌 [Errno] 메시지

이 프로그램의 목표는 경영진이 당사 소유의 웹 사이트의 HTTP 응답 및 URL 리디렉션을 캡처하는 데 사용할 수있는 휴대용 실행 파일입니다.

#!/bin/python 
import urllib, urllib2, sys, logging, time 

# Variables 
s = time.strftime('%Y%m%d%H%M%S') 
f = open("list.txt",'r') 

# Logging 
class Logger(object): 
    def __init__(self): 
     self.terminal = sys.stdout 
     self.log = open("assets_"+s+".txt", "a") 

    def write(self, message): 
     self.terminal.write(message) 
     self.log.write(message) 

# Capture logging class 
sys.stdout = Logger() 

# Text file header 
print "ASSET, STATUS, REDIRECT, DATE/TIME" 

# Feed program 16,000 URLs 
for url in f.readlines(): 
    try: 
     http_connection = 'http://' + (url) 
     connection = urllib2.urlopen(http_connection) 
     print (url).rstrip("\n"), ",", connection.getcode(), ",", connection.geturl(), ",", (s) 
     connection.close() 
    except urllib2.URLError as e: 
     print e.reason 
+0

합니까 [이 질문] (http://stackoverflow.com/questions/4847649/opening-websites-using-urllib2-from-behind-corporate-firewall-11004-getaddrinf) 도움이 필요하십니까? – bbayles

답변

-1

여기서 최종 솔루션이다. 프록시 관련이없는 곳에서 오류를 발견했습니다.

#!/bin/python 

import urllib2, sys, logging, time, errno, unittest 

# Variables 
s = time.strftime('%Y%m%d%H%M%S') 
f = open("list.txt",'r') 

# Create file text file for importing into database 
class Logger(object): 
    def __init__(self): 
     self.terminal = sys.stdout 
     self.log = open("assets_"+s+".txt", "a") 

    def write(self, message): 
     self.terminal.write(message) 
     self.log.write(message) 

# Start capture of screen output for database file 
sys.stdout = Logger() 
print "UID, ASSET, STATUS, REDIRECT, DATE/TIME" 

# Loop to capture URL status and redirect information 
for assets in f.readlines(): 
    url = assets.split() 
    if len(url) > 1: 
     try: 
      http = 'http://' + url[1]   
      http_connection = urllib2.urlopen(http, timeout=5) 
     except IOError, e: 
      if e.errno == None:   
       try: 
        www = 'http://www.' + url[1] 
        http_connection = urllib2.urlopen(www, timeout=5) 
       except IOError, e: 
        print url[0], ",", url[1].rstrip("\n"), ",", "", ",", e.errno, ",", (s) 
       else: 
        print url[0], ",", url[1].rstrip("\n"), ",", http_connection.getcode(), ",", http_connection.geturl(), ",", (s) 
     else: 
      print url[0], ",", url[1].rstrip("\n"), ",", http_connection.getcode(), ",", http_connection.geturl(), ",", (s) 
0

환경 또는 데이터 문제와 비슷합니다. 프록시에서 이걸 실행한다고 했잖아요? 이 라인을 작동시키는 작업.

연결 = urllib2.urlopen (HTTP_CONNECTION)