2009年10月18日日曜日

PythonRecipe

項目別にサンプルコードが載っており、お勧めです。
http://lightson.dip.jp/zope/ZWiki/PythonRecipe

[python]日本語のファイルを読み書きする

from codecs import open

in_file = open("before.txt", "r", "iso-2022-jp")
out_file = open("after.txt", "w", "utf-8")

for l in in_file: out_file.write(l)

in_file.close()
out_file.close()

http://d.hatena.ne.jp/yach/20080308#p1

【Python】urllib2 - http headersをセットする。

import urllib2

url = 'http://vsbabu.org/'

txdata = None
txheaders = {
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
'Accept-Language': 'en-us',
'Accept-Encoding': 'gzip, deflate, compress;q=0.9',
'Keep-Alive': '300',
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
}
req = urllib2.Request(url, txdata, txheaders)
u = urllib2.urlopen(req)
print u.info()
print u.read()
  

http://vsbabu.org/mt/archives/2003/05/27/urllib2_setting_http_headers.html

urllib2モジュール
http://d.hatena.ne.jp/yumimue/20071231/1199129495

2009年10月12日月曜日

1つのIPで複数のSSLサイトを運用する方法

Listen 443
Listen 444
NameVirtualHost aaa.bbb.ccc.ddd:443
NameVirtualHost aaa.bbb.ccc.ddd:444

<VirtualHost aaa.bbb.ccc.ddd:443>
SSLEngine on
ServerName www.hoge.com
DocumentRoot /www/httpd/www.hoge.com
ServerAdmin webmaster@www.hoge.com
ErrorLog logs/error_log
TransferLog logs/access_log
SSLCertificateFile ssl.crt/www.hoge.com.crt
SSLCertificateKeyFile ssl.key/www.hoge.com.key
</VirtualHost>

<VirtualHost aaa.bbb.ccc.ddd:444>
SSLEngine on
ServerName www.moge.net
DocumentRoot /www/httpd/www.moge.net
ServerAdmin webmaster@www.moge.net
ErrorLog logs/error_log
TransferLog logs/access_log
SSLCertificateFile ssl.crt/www.moge.com.crt
SSLCertificateKeyFile ssl.key/www.moge.com.key
</VirtualHost>
http://q.hatena.ne.jp/1175171428