IT/프로그래밍
[Python] session이 유지된 http 연결 지원 : ClientCookie
NineKY
2009. 10. 26. 16:52
Python에서 Session을 유지한 인터넷 연결은 오늘 시도해 본 결과 꽤 어렵다.
그러나, 세상 만사는 찾아보면 다 있나니,
ClientCookie 라는 라이브러리이다.
만드신 분은 내겐 그저 고마운 사람
[ 설치 과정에서의 팁 ]
설치 과정에서 에러가 하나 난다. 그것만 짚고 넘어가자.
d:\src\python\CookieClient_ZIP\ClientCookie-1.3.0\ClientCookie-1.3.0>setup.py build
---------------------------------------------------------------------------
This script requires setuptools version 0.6a11 to run (even to display
help). I will attempt to download it for you (from
http://cheeseshop.python.org/packages/2.6/s/setuptools/), but
you may need to enable firewall access for this script first.
I will start the download in 15 seconds.
(Note: if this machine does not have network access, please obtain the file
http://cheeseshop.python.org/packages/2.6/s/setuptools/setuptools-0.6a11-py2.6.egg
and place it in this directory before rerunning this script.)
---------------------------------------------------------------------------
Downloading http://cheeseshop.python.org/packages/2.6/s/setuptools/setuptools-0.6a11-py2.6.egg
Traceback (most recent call last):
File "d:\src\python\CookieClient_ZIP\ClientCookie-1.3.0\ClientCookie-1.3.0\setup.py", line 89, in
ez_setup.use_setuptools()
File "d:\src\python\CookieClient_ZIP\ClientCookie-1.3.0\ClientCookie-1.3.0\ez_setup\__init__.py", line 88, in use_setuptools
egg = download_setuptools(version, download_base, to_dir, download_delay)
File "d:\src\python\CookieClient_ZIP\ClientCookie-1.3.0\ClientCookie-1.3.0\ez_setup\__init__.py", line 142, in download_setuptools
src = urllib2.urlopen(url)
File "C:\Python26\lib\urllib2.py", line 124, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 389, in open
response = meth(req, response)
File "C:\Python26\lib\urllib2.py", line 502, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 421, in error
result = self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 597, in http_error_302
return self.parent.open(new)
File "C:\Python26\lib\urllib2.py", line 389, in open
response = meth(req, response)
File "C:\Python26\lib\urllib2.py", line 502, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 427, in error
return self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 510, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
---------------------------------------------------------------------------
This script requires setuptools version 0.6a11 to run (even to display
help). I will attempt to download it for you (from
http://cheeseshop.python.org/packages/2.6/s/setuptools/), but
you may need to enable firewall access for this script first.
I will start the download in 15 seconds.
(Note: if this machine does not have network access, please obtain the file
http://cheeseshop.python.org/packages/2.6/s/setuptools/setuptools-0.6a11-py2.6.egg
and place it in this directory before rerunning this script.)
---------------------------------------------------------------------------
Downloading http://cheeseshop.python.org/packages/2.6/s/setuptools/setuptools-0.6a11-py2.6.egg
Traceback (most recent call last):
File "d:\src\python\CookieClient_ZIP\ClientCookie-1.3.0\ClientCookie-1.3.0\setup.py", line 89, in
ez_setup.use_setuptools()
File "d:\src\python\CookieClient_ZIP\ClientCookie-1.3.0\ClientCookie-1.3.0\ez_setup\__init__.py", line 88, in use_setuptools
egg = download_setuptools(version, download_base, to_dir, download_delay)
File "d:\src\python\CookieClient_ZIP\ClientCookie-1.3.0\ClientCookie-1.3.0\ez_setup\__init__.py", line 142, in download_setuptools
src = urllib2.urlopen(url)
File "C:\Python26\lib\urllib2.py", line 124, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 389, in open
response = meth(req, response)
File "C:\Python26\lib\urllib2.py", line 502, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 421, in error
result = self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 597, in http_error_302
return self.parent.open(new)
File "C:\Python26\lib\urllib2.py", line 389, in open
response = meth(req, response)
File "C:\Python26\lib\urllib2.py", line 502, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 427, in error
return self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 510, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
이 메시지는 다운로드 URL 을 자동으로 뽑아내려는 꽁수 때문에 발생하는 문제이다.
그저 난 웃지요ㅋ
아무튼, 이런 것 때문에 시간을 허비할 수는 없는 일...
'ez_setup\__init__.py' 파일을 수정하여 해결하고 넘어가자.
그런 뒤에, __init__.py 파일의 다운로드 코드에 직접 하드코딩 하고 평상시처럼 setup.py 를 실행하면 된다.
src = urllib2.urlopen('http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
이상!!