<?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>meier-online &#187; Python</title>
	<atom:link href="http://meier-online.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://meier-online.com</link>
	<description>Der Blog von Karsten Meier</description>
	<lastBuildDate>Sun, 09 Oct 2011 13:27:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to fetch remote data with the App Engine</title>
		<link>http://meier-online.com/en/2008/08/fremde-daten-mit-der-appengine-verarbeiten/</link>
		<comments>http://meier-online.com/en/2008/08/fremde-daten-mit-der-appengine-verarbeiten/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 15:36:00 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AppEngine]]></category>
		<category><![CDATA[fetch]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://meier-online.com/blog/?p=164</guid>
		<description><![CDATA[You can use the App Engine to retrieve web pages or other information from foreign servers and process them in your python program. This must obviously be limited, because the abuse potential is very high. Therefore you can not call all possible Internet services. You can retrieve only &#8220;web pages&#8221; or everything that a Web [...]]]></description>
			<content:encoded><![CDATA[<p>You can use the App Engine to retrieve web pages or other information from foreign servers and process them in your python program.</p>
<p>This must obviously be limited, because the abuse potential is very high. Therefore you can not call all possible Internet services. You can retrieve only &#8220;web pages&#8221; or  everything that a Web server is offering on port 80 or 443.</p>
<p><span id="more-164"></span>The module urlfetch implements it. A simple usage is:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">response = urlfetch.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>
content = response.<span style="color: black;">content</span></pre></div></div>

<p>If everything goes well, this is enough. So far, this is very convienent. But in most real world scenarios, you need to handle all kind of error conditions. Like in this skeleton:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    <span style="color: #ff7700;font-weight:bold;">try</span>:
        response = urlfetch.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span>jadurl<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> response.<span style="color: black;">status_code</span> == <span style="color: #ff4500;">200</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">xxheaders</span> = response.<span style="color: black;">headers</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">xxcontent</span> = response.<span style="color: black;">content</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">xxFetched</span> = <span style="color: #008000;">True</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> response.<span style="color: black;">status_code</span> == <span style="color: #ff4500;">404</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">errortext</span> = <span style="color: #483d8b;">&quot;File not found&quot;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">xxcontent</span> = <span style="color: #483d8b;">&quot;not found&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">errortext</span> = <span style="color: #483d8b;">&quot;Bad Response Code&quot;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">xxcontent</span> = response.<span style="color: black;">status_code</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> InvalidURLError:
        <span style="color: #008000;">self</span>.<span style="color: black;">errortext</span> = <span style="color: #483d8b;">&quot;Invalid URL&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> DownloadError:
        <span style="color: #008000;">self</span>.<span style="color: black;">errortext</span> = <span style="color: #483d8b;">&quot;Error downloading file&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> ResponseTooLargeError:
        <span style="color: #008000;">self</span>.<span style="color: black;">errortext</span> = <span style="color: #483d8b;">&quot;File to large&quot;</span></pre></div></div>

<h3>HTTP-Headers</h3>
<p style="margin-bottom: 0cm;">You can also access to the HTTP headers. For example, if you want to access the mime type:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">response.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'content-type'</span><span style="color: black;">&#93;</span></pre></div></div>

<p>In my particular use case I am also interested whether a header is sent twice. It seems that you can not get this information.</p>
<h3>SSL</h3>
<p>You can also access SSL-protected pages with &#8220;https: / / . Unfortunately,  according to the documentation as of version 1.1, the certificate is not checked. This means, the increased security is not there. This restricts the possible application range.</p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2008/08/fremde-daten-mit-der-appengine-verarbeiten/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upload Files with the AppEngine</title>
		<link>http://meier-online.com/en/2008/07/dateiupload-mit-der-appengine/</link>
		<comments>http://meier-online.com/en/2008/07/dateiupload-mit-der-appengine/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 15:26:00 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AppEngine]]></category>
		<category><![CDATA[Dateiupload]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://meier-online.com/blog/?p=166</guid>
		<description><![CDATA[If you want process an uploaded file in a cgi-programm, you often need to juggle with temporary files. How to do it with the Python in the AppEngine? Because you don&#8217;t have write access to a traditonal file system in this highly distrubuted environment. I have searched a while in the documentation. Finally, in an [...]]]></description>
			<content:encoded><![CDATA[<p>If you want process an uploaded file in a cgi-programm, you often need to juggle with temporary files. How to do it with the Python in the AppEngine? Because you don&#8217;t have write access to a traditonal file system in this highly distrubuted environment. I have searched a while in the documentation. Finally, in an example for picture processing, I found the solution.</p>
<p><span id="more-166"></span>It was just too easy. If you have a HTML input field of type &#8220;file&#8221; with the name &#8220;Uploadfile&#8221;, you can access the uploaded data like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">filecontent = <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span> <span style="color: black;">&#40;</span> <span style="color: #483d8b;">'Uploadfile'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Then the file content is then stored in the variable &#8220;filecontent&#8221;. If it happens to be a text file, You can process it like a normal string.</p>
<p>For many applications this is  and sufficient and very convenient. A few questions are still open for me:</p>
<ul>
<li>How to get the original filename?</li>
<li>If the uploaded file is very big, how can I block further processing as early as possible?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2008/07/dateiupload-mit-der-appengine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>App Engine: first notes</title>
		<link>http://meier-online.com/en/2008/07/app-engine/</link>
		<comments>http://meier-online.com/en/2008/07/app-engine/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 17:48:00 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AppEngine]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://meier-online.com/blog/?p=9</guid>
		<description><![CDATA[My first impressions and some notes about programming for Googles App Engine.]]></description>
			<content:encoded><![CDATA[<p>Google makes it possible to run own web applications on their servers. I tried out their offer. Here are my first notes:<br />
Requirement is the programming language Python. There is an SDK, which let you run  your applications on your own computer before uploading. An there is also a tutorial.<br />
I installed the SDK in version 1.1 and checked out the tutorial.<br />
<span id="more-9"></span><br />
The SDK comes with its own webserver. You start the server with</p>
<pre>$ dev_appserver.py helloworld</pre>
<p>In the directory there  must be a configuration file in the format Yaml. This file matches URLs to Python files or to images, etc . If the file does not exist, or it does not contain the required information, an exception is thrown.</p>
<p>Some files will be automatically created, and you can forget them easily:<br />
a configuration file of the SDK in your userdir in file &#8220;.appcfg_nag&#8221; and a data store (practically the database) in userdir \ temp \ dev_appserver.datastore</p>
<p>Included is a small framework called WebApp.<br />
It separates  the Python code from HTML code. There is a template engine with Django-compatible syntax.<br />
I had a problem with the templates, the XML header ()<br />
at the beginning caused my browser not not display the result.</p>
<p>The template language itself uses curly brackets. This is quite compact, unfortunately, the template can be quickly leed to degenerated  HTML code, you can non verify the template itself in the browser.</p>
<p>The Web application uses neither the otherwise ubiquitous SQL databases nor the file system to save data. Instead there is a special storage. Ver nice is: you can simply inherit a class from &#8220;db.Model&#8221;, and you can read and write complete objects to the data store. You do not take care of the instance variables, and you also do not declare any database tables. An SQL-like query language is also available, but apparently this is more &#8220;syntactic sugar&#8221; than real SQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2008/07/app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

