Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Backport snapshot capturing via requests from 4f5dc70 to release branch #1078

Closed
krisp opened this issue Oct 2, 2015 · 4 comments
Labels
good first issue A good first issue for someone new to OctoPrint's development request Feature request

Comments

@krisp
Copy link

krisp commented Oct 2, 2015

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.

I 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.

This patch changes timelapse.py from urllib to requests and writes jpegs in 1kb chunks rather than storing the whole image in ram.

--- a/timelapse.py        2015-09-01 10:42:50.205005558 -0400
+++ b/timelapse.py       2015-10-01 22:12:25.853462979 -0400
@@ -6,7 +6,7 @@
 import logging
 import os
 import threading
-import urllib
+import requests
 import time
 import subprocess
 import fnmatch
@@ -251,7 +251,13 @@
        def _captureWorker(self, filename):
                eventManager().fire(Events.CAPTURE_START, {"file": filename})
                try:
-                       urllib.urlretrieve(self._snapshotUrl, filename)
+                       r = requests.get(self._snapshotUrl, stream=True)
+                       with open(filename, "wb") as fd:
+                         for chunk in r.iter_content(chunk_size=1024):
+                           if chunk:
+                             fd.write(chunk)
+                             fd.flush()
+
                        self._logger.debug("Image %s captured from %s" % (filename, self._snapshotUrl))
                except:
                        self._logger.exception("Could not capture image %s from %s, decreasing image counter again" % (filename, self._snapshotUrl))
  1. What were you doing?
  2. What did you expect to happen?
  3. What happened instead?
  4. Branch & Commit or Version of OctoPrint:
  5. Printer model & used firmware incl. version
    (if applicable - always include if unsure):
  6. Browser and Version of Browser, Operating
    System running Browser (if applicable - always
    include if unsure):
  7. Link to octoprint.log on gist.github.com or pastebin.com
    (ALWAYS INCLUDE AND DO NOT TRUNCATE):
  8. Link to contents of terminal tab or serial.log on
    gist.github.com or pastebin.com (if applicable - always
    include if unsure or reporting communication issues AND
    DO NOT TRUNCATE):
  9. Link to contents of Javascript console in the browser
    on gist.github.com or pastebin.com or alternatively a
    screenshot (if applicable - always include if unsure
    or reporting UI issues):
  10. Screenshot(s) showing the problem (if applicable - always
    include if unsure or reporting UI issues):

I have read the FAQ.

@GitIssueBot
Copy link

Hi @krisp,

It looks like there is some information missing from your ticket that will be needed in order to process it properly. Please take a look at the Contribution Guidelines and the page How to file a bug report on the project wiki, which will tell you exactly what your ticket has to contain in order to be processable.

If you did not intend to report a bug, please take special note of the title format to use as described in the Contribution Guidelines.

I'm marking this one now as needing some more information. Please understand that if you do not provide that information within the next two weeks (until 2015-10-16 02:40) I'll close this ticket so it doesn't clutter the bug tracker. This is nothing personal, so please just be considerate and help the maintainers solve this problem quickly by following the guidelines linked above. Thank you!

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being, so don't expect any replies from me :) Your ticket is read by humans too, I'm just not one of them.

@krisp krisp changed the title urllib timeout capturing timelapse images from Blue Iris (with patch) [brainstorming] urllib timeout capturing timelapse images from Blue Iris (with patch) Oct 2, 2015
@GitIssueBot GitIssueBot added brainstorming Obsolete: Development discussions. Use the forum instead. and removed status:incomplete ticket labels Oct 2, 2015
@foosel
Copy link
Member

foosel commented Oct 2, 2015

I already did that on July 20th on the devel branch (see https://github.com/foosel/OctoPrint/blob/devel/src/octoprint/timelapse.py#L302) - the code is even pretty much identical. I'll look into including the change into the maintenance branch however so it will be included into 1.2.7 and your webcam will work with the current release versions as well, not just the development version :)

@foosel foosel changed the title [brainstorming] urllib timeout capturing timelapse images from Blue Iris (with patch) [Request] Backport snapshot capturing via requests from 4f5dc70 to release branch Oct 2, 2015
@foosel foosel added request Feature request good first issue A good first issue for someone new to OctoPrint's development and removed brainstorming Obsolete: Development discussions. Use the forum instead. labels Oct 2, 2015
@foosel
Copy link
Member

foosel commented Oct 3, 2015

Ported to maintenancen branch, will be included in 1.2.7 release.

@foosel foosel closed this as completed Oct 3, 2015
@krisp
Copy link
Author

krisp commented Oct 3, 2015

super, thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue A good first issue for someone new to OctoPrint's development request Feature request
Projects
None yet
Development

No branches or pull requests

3 participants