{"action":"closed","issue":{"url":"https://api.github.com/repos/foosel/OctoPrint/issues/1078","labels_url":"https://api.github.com/repos/foosel/OctoPrint/issues/1078/labels{/name}","comments_url":"https://api.github.com/repos/foosel/OctoPrint/issues/1078/comments","events_url":"https://api.github.com/repos/foosel/OctoPrint/issues/1078/events","html_url":"https://github.com/foosel/OctoPrint/issues/1078","id":109420113,"number":1078,"title":"[Request] Backport snapshot capturing via requests from 4f5dc70 to release branch","user":{"login":"krisp","id":196791,"avatar_url":"https://avatars.githubusercontent.com/u/196791?v=3","gravatar_id":"","url":"https://api.github.com/users/krisp","html_url":"https://github.com/krisp","followers_url":"https://api.github.com/users/krisp/followers","following_url":"https://api.github.com/users/krisp/following{/other_user}","gists_url":"https://api.github.com/users/krisp/gists{/gist_id}","starred_url":"https://api.github.com/users/krisp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krisp/subscriptions","organizations_url":"https://api.github.com/users/krisp/orgs","repos_url":"https://api.github.com/users/krisp/repos","events_url":"https://api.github.com/users/krisp/events{/privacy}","received_events_url":"https://api.github.com/users/krisp/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/foosel/OctoPrint/labels/difficulty:easy","name":"difficulty:easy","color":"bfdadc"},{"url":"https://api.github.com/repos/foosel/OctoPrint/labels/type:request","name":"type:request","color":"0052cc"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-02T02:35:00Z","updated_at":"2015-10-03T19:49:44Z","closed_at":"2015-10-03T19:49:44Z","body":"I am using a popular CCTV package called Blue Iris to manage cameras around my property, so I also have the IP camera watching the 3d printer hooked into it so I can monitor along with everything else. To that end, I have had no success getting the OctoPrint timelapse feature to work downloading still images from the correct URL. I could view the jpeg in the browser and wget and curl the jpeg on the octoprint vm. However, timelapse.py would always throw a urllib timeout error when trying to pull a snapshot.\r\n\r\nI spent a few minutes debugging this with urllib and httprequest debugging enabled and found that urllib.urlretrieve() would connect to blue iris' http server but hang forever retrieving the image. Since this behavior is different than curl and wget I figured it must be something with urllib and tested using python's \"requests\" library instead which works fine with Blue Iris and should work with any other web server.\r\n\r\nThis patch changes timelapse.py from urllib to requests and writes jpegs in 1kb chunks rather than storing the whole image in ram.\r\n\r\n```python\r\n--- a/timelapse.py        2015-09-01 10:42:50.205005558 -0400\r\n+++ b/timelapse.py       2015-10-01 22:12:25.853462979 -0400\r\n@@ -6,7 +6,7 @@\r\n import logging\r\n import os\r\n import threading\r\n-import urllib\r\n+import requests\r\n import time\r\n import subprocess\r\n import fnmatch\r\n@@ -251,7 +251,13 @@\r\n        def _captureWorker(self, filename):\r\n                eventManager().fire(Events.CAPTURE_START, {\"file\": filename})\r\n                try:\r\n-                       urllib.urlretrieve(self._snapshotUrl, filename)\r\n+                       r = requests.get(self._snapshotUrl, stream=True)\r\n+                       with open(filename, \"wb\") as fd:\r\n+                         for chunk in r.iter_content(chunk_size=1024):\r\n+                           if chunk:\r\n+                             fd.write(chunk)\r\n+                             fd.flush()\r\n+\r\n                        self._logger.debug(\"Image %s captured from %s\" % (filename, self._snapshotUrl))\r\n                except:\r\n                        self._logger.exception(\"Could not capture image %s from %s, decreasing image counter again\" % (filename, self._snapshotUrl))\r\n```\r\n\r\n1. What were you doing?\r\n\r\n2. What did you expect to happen?\r\n\r\n3. What happened instead?\r\n\r\n4. Branch & Commit or Version of OctoPrint:\r\n\r\n5. Printer model & used firmware incl. version\r\n   (if applicable - always include if unsure):\r\n\r\n6. Browser and Version of Browser, Operating \r\n   System running Browser (if applicable - always \r\n   include if unsure):\r\n\r\n7. Link to octoprint.log on gist.github.com or pastebin.com\r\n   (ALWAYS INCLUDE AND DO NOT TRUNCATE):\r\n\r\n8. Link to contents of terminal tab or serial.log on \r\n   gist.github.com or pastebin.com (if applicable - always \r\n   include if unsure or reporting communication issues AND\r\n   DO NOT TRUNCATE):\r\n\r\n9. Link to contents of Javascript console in the browser \r\n   on gist.github.com or pastebin.com or alternatively a\r\n   screenshot (if applicable - always include if unsure\r\n   or reporting UI issues):\r\n\r\n10. Screenshot(s) showing the problem (if applicable - always\r\n    include if unsure or reporting UI issues):\r\n\r\nI have read the FAQ."}}