SliceInfoJob.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Job import Job
  4. from UM.Logger import Logger
  5. from UM.Platform import Platform
  6. import ssl
  7. import urllib.request
  8. import urllib.error
  9. import certifi
  10. class SliceInfoJob(Job):
  11. def __init__(self, url, data):
  12. super().__init__()
  13. self._url = url
  14. self._data = data
  15. def run(self):
  16. if not self._url or not self._data:
  17. Logger.log("e", "URL or DATA for sending slice info was not set!")
  18. return
  19. # CURA-6698 Create an SSL context and use certifi CA certificates for verification.
  20. context = ssl.SSLContext(protocol = ssl.PROTOCOL_TLSv1_2)
  21. context.load_verify_locations(cafile = certifi.where())
  22. # Submit data
  23. kwoptions = {"data": self._data,
  24. "timeout": 5,
  25. "context": context}
  26. Logger.log("i", "Sending anonymous slice info to [%s]...", self._url)
  27. try:
  28. f = urllib.request.urlopen(self._url, **kwoptions)
  29. Logger.log("i", "Sent anonymous slice info.")
  30. f.close()
  31. except urllib.error.HTTPError:
  32. Logger.logException("e", "An HTTP error occurred while trying to send slice information")
  33. except Exception: # We don't want any exception to cause problems
  34. Logger.logException("e", "An exception occurred while trying to send slice information")