<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>yken.org &#187; python</title>
	<atom:link href="http://yken.org/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://yken.org</link>
	<description>...it depends</description>
	<lastBuildDate>Sun, 07 Mar 2010 17:47:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google App Engine &#8211; the first experiences</title>
		<link>http://yken.org/2010/01/26/google-app-engine-the-first-experiences/</link>
		<comments>http://yken.org/2010/01/26/google-app-engine-the-first-experiences/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 22:36:52 +0000</pubDate>
		<dc:creator>ikendra</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[corporatepoems.com]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://yken.org/?p=334</guid>
		<description><![CDATA[A few days ago, I started to work on the corporatepoems.com website. The web is a fun pet project, an idea born somewhere in a pub after a few beers &#8211; I will write about the idea a bit later. Today, I just wanted to briefly comment on two problems which I encountered during my [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, I started to work on the <a href="http://www.corporatepoems.com/">corporatepoems.com</a> website. The web is a fun pet project, an idea born somewhere in a pub after a few beers &#8211; I will write about the idea a bit later. Today, I just wanted to briefly comment on two problems which I encountered during my first steps with the App Engine.<br />
<span id="more-334"></span></p>
<h5>Occasional blank pages</h5>
<p>If you see a blank page when refreshing your app in a browser after a source code update, be it on your local machine or after the upload to Google, but then with any subsequent refresh the page appearing just fine, check the Python script executed for given URL (see your <code>app.yaml</code>) to make sure that you are invoking the main() function correctly, i.e. something like the notorious</p>
<pre>
if __name__ == '__main__':
	main()
</pre>
<p>If you make a typo in the above snippet or should you omit it completely, you will experience the problem above.</p>
<p><b>Update:</b> See the comments below this article for explanation of the reason of this behavior.</p>
<h5>Static files: CSS not loading</h5>
<p>At some stage of working on the project I introduced the CSS style sheet for the site: added a <code>static_dir</code> to <code>handlers</code> section of the <code>app.yaml file</code> and then created the CSS file and stored it in the directory referred to by <code>static_dir</code>. Then, I simply referenced the CSS file in the HTML. So my <code>app.yaml</code> looked like</p>
<pre>
application: corporatepoems
version: 5
runtime: python
api_version: 1

handlers:
- url: /css
  static_dir: css

- url: /.*
  script: corporatepoems.py
</pre>
<p>&#8230;and the HTML contained:</p>
<pre>
&lt;link rel="stylesheet" href="/css/corporatepoems.css" type="text/css" media="screen" /&gt;
</pre>
<p>However, the CSS would not load. I double checked the file and directory names, all was correct. The fix to the problem was to actually increase (or chage) the application <code>version</code> in the <code>app.yaml</code> file. After that, CSS loaded as expected. The explanation to this could be that I perhaps forgotten to save the <code>app.yaml</code> file after adding the <code>static_dir</code> at first place, but I&#8217;m pretty sure this was not the case. After the fix, I never saw the problem again.</p>
<p>All in all, working with Google App Engine and Python feels great so far, thanks Filip for your suggestion to give it a try! To be continued. </p>
]]></content:encoded>
			<wfw:commentRss>http://yken.org/2010/01/26/google-app-engine-the-first-experiences/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up mod_wsgi with XAMPP on a Mac</title>
		<link>http://yken.org/2009/09/17/setting-up-mod_wsgi-with-xampp-on-a-mac/</link>
		<comments>http://yken.org/2009/09/17/setting-up-mod_wsgi-with-xampp-on-a-mac/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 19:37:37 +0000</pubDate>
		<dc:creator>ikendra</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://yken.org/?p=213</guid>
		<description><![CDATA[For a project at work I needed to create a Python app, accessible via http. I&#8217;m using a Mac with XAMPP installed at work. Being used to do this sort of work mostly in PHP, I needed to learn a few things. Here is the summary of how to make it work on the localhost.

Download [...]]]></description>
			<content:encoded><![CDATA[<p>For a project at work I needed to create a Python app, accessible via http. I&#8217;m using a Mac with XAMPP installed at work. Being used to do this sort of work mostly in PHP, I needed to learn a few things. Here is the summary of how to make it work on the localhost.</p>
<p><span id="more-213"></span></p>
<h5>Download mod_wsgi</h5>
<p>Python WSGI is a specification of interface between web servers and Python applications or application frameworks.  The mod_wsgi is an Apache module, using which it is possible to access Python applications (which adhere to WSGI speficiation) via http.</p>
<p>The mod_wsgi can be downloaded from <a href="http://code.google.com/p/modwsgi/">http://code.google.com/p/modwsgi/</a>.</p>
<h5>Compile and install mod_wsgi</h5>
<p>Versions used: Python 2.5.1, apache 2.2.11, mod_wsgi 2.3</p>
<p>Unpack the mod_wsgi and run the usual:</p>
<pre>
$ ./configure
$ make
$ sudo make install
</pre>
<p>On my Mac, the module was installed to <code>/usr/libexec/apache2</code>, I had to copy it manually to XAMPP location:</p>
<pre>
$ sudo cp /usr/libexec/apache2/mod_wsgi.so /Applications/xampp/xamppfiles/modules/
</pre>
<h5>Write a sample Python WSGI application</h5>
<p>The next step is to create a directory where the Python application will be stored. Unlike with PHP scripts, Apache server needs to be made aware of exact location of the app. We also have to tell Apache which particular script needs to be executed for any http request which points to the application directory. This is also very different from what you might be used to with PHP. To be able to do all the configuration changes in <code>httpd.conf</code>, we first need to create a directory and to create the main application script so we can write down all directory and file names required.</p>
<pre>
[ivk@ivk-mbpro /Applications/xampp/xamppfiles/htdocs]$ mkdir app-sample
[ivk@ivk-mbpro /Applications/xampp/xamppfiles/htdocs]$ cd app-sample
[ivk@ivk-mbpro /Applications/xampp/xamppfiles/htdocs/app-sample]$ vi main.py
</pre>
<p><code>main.py</code> can be for instance a simple Hello World! app:</p>
<pre>
def application(env, start_response):
    start_response("200 OK", [])
    output = "&lt;html&gt;Hello World! Request: %s&lt;/html&gt;"
    output %= env['PATH_INFO']
    return [output]
</pre>
<h5>Put it all together</h5>
<p>Modify the <code>httpd.conf</code> by adding the following:</p>
<pre>
LoadModule wsgi_module modules/mod_wsgi.so

WSGIScriptAlias /app-sample "/Applications/xampp/xamppfiles/htdocs/app-sample/main.py"
&lt;Directory "/Applications/xampp/xamppfiles/htdocs/app-sample"&gt;
    Order deny,allow
    Allow from all
&lt;/Directory&gt;
</pre>
<p><code>WSGIScriptAlias</code> directive makes sure that for all requests to <code>/app-sample</code>, the <code>"/Applications/xampp/xamppfiles/htdocs/app-sample/main.py"</code>will be executed by Python.</p>
<p>Modify <code>mime.types</code> by adding &#8220;py&#8221; as follows:</p>
<pre>
text/html        html htm py
</pre>
<p>After Apache restart you should be able to access your python script <code>main.py</code> via http:</p>
<p><img src="http://yken.org/wp-content/python-sample-app-wsgi.jpg" alt="python-sample-app-wsgi" title="python-sample-app-wsgi" width="512" height="432" class="alignleft size-full wp-image-223" /></p>
]]></content:encoded>
			<wfw:commentRss>http://yken.org/2009/09/17/setting-up-mod_wsgi-with-xampp-on-a-mac/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
