Skip to main content

Posts

Showing posts from June, 2010

Serve file downloading in Turbogears 1.0.x

You may want to generate a .csv file using StringIO for downloading, here is how to do it in Turbogears 1.0.x: @expose(content_type='text/csv',format="csv") def csvdownload(self,**kw):     file = cStringIO.StringIO()     file.write('a,b,c\n')     cherrypy.response.headerMap["Content-Disposition"] ='attachment;filename=stats.csv'     return file.getvalue()

Install Scribe on Ubuntu

Scribe is a very useful tools for collecting logs in the cloud. Here is an simple instruction for installing scribe on Ubuntu(based on those articles: link1 link2 link3 ). First, install libevent, boost and thrift: sudo apt-get install libevent-dev sudo apt-get install libboost-dev=1.38.1 flex bison libtool automake autoconf pkg-config wget http://archive.apache.org/dist/incubator/thrift/0.4.0-incubating/thrift-0.4.0.tar.gz cd thrift && ./bootstrap.sh && ./configure && make && sudo make install cd contrib/fb303/ ./bootstrap.sh && sudo make && sudo make install If libboost-dev 1.38.1 is not found, version 1.40 is OK. Second, get scribe(from http://github.com/facebook/scribe/downloads ) installed: ./bootstrap.sh ./configure sudo make && sudo make install During the make of scribe, you may get following errors: 1) "configure: error: Could not link against !"try sudo apt-get install libboost-all-dev 2)"

400 Bad Request Issue with urllib2

In python 2.5, urllib2.urlopen may lead to "HTTPError: HTTP Error 400: Bad Request" sometimes(such as google checkout xml api). This may be caused by a bug . According to this post , we may use httplib instead. Take google checkout for example: url = '/checkout/api/checkout/v2/request/Merchant/%s'%merchant_id conn = httplib.HTTPSConnection('sandbox.google.com') headers = {} headers['Authorization'] = 'Basic %s' % ( base64.b64encode(merchant_id + ':' + merchant_key)) headers['Content-type'] = 'application/xml; charset=UTF-8' headers['Accept'] =' application/xml; charset=UTF-8' conn.request("POST", url, shopcart_xml_info, headers) response = conn.getresponse() return response.read()