2014-09-05 3 views
0

프록시를 사용하여 orginizational 방화벽을 통해 http 웹 서비스에 액세스하려고합니다. 서비스에 액세스하려면 서비스 공급자의 https 연결을 사용하여 토큰을 생성해야합니다. 몇 가지 이유를 들어 프록시를 통해 내 연결이 실패하고 파이썬 인터프리터는 splituser 데프 내부 _userprog 다루는 URLLIB에 라인 1072에서 오류를 던지고있다 :urllib splituser에서 파이썬 프록시 연결이 실패 함 _userprog

corrosponding 오류 텍스트가됩니다
match = _userprog.match(host) 

'예상 문자열 또는 버퍼' . 나는 명령 줄에서 SETX를 사용하여 환경 변수로 모두 HTTP_PROXY와 https_proxy를 추가 ...

SETX http_proxy http:\\user:[email protected]:port 
SETX https_proxy https:\\user:[email protected]:port 

... 그리고 내 스크립트의 GetToken 코드 전에 프록시 처리기를 추가 한 :

# set proxies 
proxy = urllib2.ProxyHandler({ 
    'http': 'proxy_ip', 
    'https': 'proxy_ip' 
}) 
opener = urllib2.build_opener(proxy) 
urllib2.install_opener(opener) 

class GetToken(object): 
     def urlopen(self, url, data=None): 
     # open url, send response 
     referer = "http://www.arcgis.com/arcgis/rest" 
     req = urllib2.Request(url) 
     req.add_header('Referer', referer) 
     if data: 
      response = urllib2.urlopen(req, data) 
     else: 
      response = urllib2.urlopen(req) 
     return response 

    def gentoken(self, username, password, 
     referer = 'www.arcgis.com', expiration=60): 
     # gets token from referrer 
     query_dict = {'username': username, 
      'password': password, 
      'expiration': str(expiration), 
      'client': 'referer', 
      'referer': referer, 
      'f': 'json'} 
     query_string = urllib.urlencode(query_dict) 
     token_url = "https://www.arcgis.com/sharing/rest/generateToken" 
     token_response = urllib.urlopen(token_url, query_string) 
     token = json.loads(token_response.read()) 
     if "token" not in token: 
      print token['messages'] 
      exit() 
     else: 
      return token['token'] 

하지만 여전히 같은 오류가 발생합니다. 어떤 조언을 주셔서 감사 드리며 미리 감사드립니다!

UPDATE

덕분에 일을 변경 슬래시 제안에 대한 mhawke ...하지만 지금은 새로운 오류가있어, 여기에 역 추적입니다 :

Traceback    
    <module> C:\Users\tle\Desktop\Scripts\dl_extract2.py 161  
    main C:\Users\tle\Desktop\Scripts\dl_extract2.py 157  
    __init__ C:\Users\tle\Desktop\Scripts\dl_extract2.py 53  
    gentoken C:\Users\tle\Desktop\Scripts\dl_extract2.py 40  
    urlopen C:\Python26\ArcGIS10.0\lib\urllib.py 88  
    open C:\Python26\ArcGIS10.0\lib\urllib.py 207  
    open_https C:\Python26\ArcGIS10.0\lib\urllib.py 439  
    endheaders C:\Python26\ArcGIS10.0\lib\httplib.py 904  
    _send_output C:\Python26\ArcGIS10.0\lib\httplib.py 776  
    send C:\Python26\ArcGIS10.0\lib\httplib.py 735  
    connect C:\Python26\ArcGIS10.0\lib\httplib.py 1112   
    wrap_socket C:\Python26\ArcGIS10.0\lib\ssl.py 350  
    __init__ C:\Python26\ArcGIS10.0\lib\ssl.py 118  
    do_handshake C:\Python26\ArcGIS10.0\lib\ssl.py 293  
IOError: [Errno socket error] [Errno 1] _ssl.c:480: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol 

업데이트 2

은 mhawke의 제안에 따라 핸드 셰이크 오류를 제거하는 토큰을 생성하기 위해 https 연결에 urllib() 대신 urllib2()를 사용하여 시도했습니다. 불행하게도 지금은 시간 초과 오류가있는 사각형으로 되돌아갑니다.이 시간은 urllib2의 1136 줄에 던져졌습니다. urllib2가 https 연결을 지원하지 않기 때문입니다. 이것은 또한 내 프록시가 HTTP 터널링을 지원하지 않는다는 것을 의미합니까, 아니면 내 로컬 컴퓨터에서 테스트 할 수있는 방법이 있습니까? - 시스템 환경 변수는 (내 경우) 필요한 모든 이것은 정말 쉽게 수정으로 밝혀졌다 3

Traceback    
    <module> C:\Users\tle\Desktop\Scripts\dl_extract2.py 161  
    main C:\Users\tle\Desktop\Scripts\dl_extract2.py 157  
    __init__ C:\Users\tle\Desktop\Scripts\dl_extract2.py 53  
    gentoken C:\Users\tle\Desktop\Scripts\dl_extract2.py 40  
    urlopen C:\Python26\ArcGIS10.0\lib\urllib2.py 126  
    open C:\Python26\ArcGIS10.0\lib\urllib2.py 391  
    _open C:\Python26\ArcGIS10.0\lib\urllib2.py 409  
    _call_chain C:\Python26\ArcGIS10.0\lib\urllib2.py 369  
    https_open C:\Python26\ArcGIS10.0\lib\urllib2.py 1169   
    do_open C:\Python26\ArcGIS10.0\lib\urllib2.py 1136   
URLError: <urlopen error [Errno 10060] Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat> 

UPDATE : 어떤 경우에, 여기에서 최신 역 추적입니다 정상 슬래시 :

http_proxy: http://user:[email protected]:port 
https_proxy: http://user:[email protected]:port 

하고 스크립트에서 제거 다음 코드 :

proxy = urllib2.ProxyHandler({ 
    'http': 'proxy_ip', 
    'https': 'proxy_ip' 
}) 
opener = urllib2.build_opener(proxy) 
urllib2.install_opener(opener) 
,536,913,632 10

이 링크 방법에 대해 설명하고이 작동하는 이유 :

http://lukasa.co.uk/2013/07/Python_Requests_And_Proxies/

+0

전체 추적을 게시하고 'http': 'proxy_ip'에 사용중인 것을 보여주십시오. – mhawke

+0

또한 백 슬래시를 사용하는 대신 URL에 슬래시 (예 : http : // user : pw @ proxyIP)를 사용해보십시오. : port' – mhawke

+0

proxy_ip : "192.168.104.103" –

답변

관련 문제