{"id":164,"date":"2008-08-06T15:36:00","date_gmt":"2008-08-06T15:36:00","guid":{"rendered":"http:\/\/meier-online.com\/blog\/?p=164"},"modified":"2013-11-29T13:54:28","modified_gmt":"2013-11-29T12:54:28","slug":"fremde-daten-mit-der-appengine-verarbeiten","status":"publish","type":"post","link":"https:\/\/meier-online.com\/en\/2008\/08\/fremde-daten-mit-der-appengine-verarbeiten\/","title":{"rendered":"How to fetch remote data with the App Engine"},"content":{"rendered":"<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>\n<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>\n<p><!--more-->The module urlfetch implements it. A simple usage is:<\/p>\n<pre lang=\"python\">response = urlfetch.fetch(url)\r\ncontent = response.content<\/pre>\n<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>\n<pre lang=\"python\">    try:\r\n        response = urlfetch.fetch(jadurl)\r\n        if response.status_code == 200:\r\n            self.xxheaders = response.headers\r\n            self.xxcontent = response.content\r\n            self.xxFetched = True\r\n        elif response.status_code == 404:\r\n            self.errortext = \"File not found\"\r\n            self.xxcontent = \"not found\"\r\n        else:\r\n            self.errortext = \"Bad Response Code\"\r\n            self.xxcontent = response.status_code\r\n    except InvalidURLError:\r\n        self.errortext = \"Invalid URL\"\r\n    except DownloadError:\r\n        self.errortext = \"Error downloading file\"\r\n    except ResponseTooLargeError:\r\n        self.errortext = \"File to large\"<\/pre>\n<h3>HTTP-Headers<\/h3>\n<p style=\"margin-bottom: 0cm;\">You can also access to the HTTP headers. For example, if you want to access the mime type:<\/p>\n<pre lang=\"python\">response.headers['content-type']<\/pre>\n<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>\n<h3>SSL<\/h3>\n<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>","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/meier-online.com\/en\/2008\/08\/fremde-daten-mit-der-appengine-verarbeiten\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to fetch remote data with the App Engine&#8221;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[104],"tags":[70,194,96,124,196,98,94],"class_list":["post-164","post","type-post","status-publish","format-standard","hentry","category-develop","tag-appengine","tag-cloud","tag-fetch","tag-howto","tag-mashup","tag-python","tag-ssl","entry"],"_links":{"self":[{"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/posts\/164"}],"collection":[{"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":12,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":1456,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/posts\/164\/revisions\/1456"}],"wp:attachment":[{"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}