AstroPrint / OctoPrint-AstroPrint

Connect your OctoPrint device to the AstroPrint 3D Printing Cloud
31 stars 10 forks source link

fix for python 3 #88

Closed GiulianoSpaghetti closed 4 years ago

GiulianoSpaghetti commented 4 years ago

in init.py i changed Queue with queue in AstroDB.py the changes are most significant.

CoDanny commented 4 years ago

Thanks for the PR. We will validate and merge during next week. Much appreciated.

CoDanny commented 4 years ago

@numerunix did something not work under the Py3 environment? We have tested it. Is this PR an improvement or a fix?

GiulianoSpaghetti commented 4 years ago

It's only a fix. I've tested both via app and using web interface all except the commands for moving the extrusor because the app tells me that I must be in the same network of the printer, but the python engine does not rise any exception.

CoDanny commented 4 years ago

@numerunix Sorry I think I wasn't clear in my previous question. What I meant to say is what prompted you to create this PR? Was it because something failed and the PR fixes it or did you inspect the code and saw some improvements but the previous code also worked?

I'd like to know this because the code before the PR didn't fail in our tests.

GiulianoSpaghetti commented 4 years ago

I have an old centrino machine that runs debian 10 32 bit with latests official debian updates. I've installed octoprint using "pip3 install" on my machine and then i downloaded the plugin using the plugin manager of octoprint. On my machine that plugin faults, so i fixed it. Python3 rises some exceptions.

CoDanny commented 4 years ago

Ok. Thanks

sl1pkn07 commented 4 years ago
2020-04-12 01:54:02,901 - octoprint.plugin.core - ERROR - Error loading plugin astroprint
Traceback (most recent call last):
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/plugin/core.py", line 972, in _import_plugin
    module = _load_module(module_name, spec)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/plugin/core.py", line 71, in _load_module
    return imp.load_module(name, f, filename, details)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/vendor/imp.py", line 241, in load_module
    return load_package(name, filename)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/vendor/imp.py", line 215, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint_astroprint/__init__.py", line 18, in <module>
    from .AstroprintCloud import AstroprintCloud
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint_astroprint/AstroprintCloud.py", line 12, in <module>
    from .downloadmanager import DownloadManager
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint_astroprint/downloadmanager/__init__.py", line 12, in <module>
    from Queue import Queue
ModuleNotFoundError: No module named 'Queue'

fixed with this:

try:
   import queue
except ImportError:
   import Queue as queue

(https://stackoverflow.com/questions/33432426/importerror-no-module-named-queue)

but..

2020-04-12 02:09:49,292 - octoprint.plugin.core - ERROR - Error loading plugin astroprint
Traceback (most recent call last):
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/plugin/core.py", line 972, in _import_plugin
    module = _load_module(module_name, spec)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/plugin/core.py", line 71, in _load_module
    return imp.load_module(name, f, filename, details)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/vendor/imp.py", line 241, in load_module
    return load_package(name, filename)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/vendor/imp.py", line 215, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint_astroprint/__init__.py", line 22, in <module>
    from .cameramanager import cameraManager
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint_astroprint/cameramanager/__init__.py", line 13, in <module>
    from StringIO import StringIO
ModuleNotFoundError: No module named 'StringIO'

fixed with

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

(https://github.com/nahamsec/JSParser/issues/18#issuecomment-366506351)

but again...

Traceback (most recent call last):
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint/plugin/__init__.py", line 230, in call_plugin
    result = getattr(plugin, method)(*args, **kwargs)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint_astroprint/__init__.py", line 142, in on_after_startup
    self.astroprintCloud = AstroprintCloud(self)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint_astroprint/AstroprintCloud.py", line 40, in __init__
    self.downloadmanager = DownloadManager(self)
  File "/opt/octoprint-git/lib/python3.8/site-packages/octoprint_astroprint/downloadmanager/__init__.py", line 166, in __init__
    self.queue = Queue()
NameError: name 'Queue' is not defined
GiulianoSpaghetti commented 4 years ago

Hello and happy easter

StringIO has module changed from python2 to python3. change to this from io import StringIO

I don't remember any other change i made to this new version, so it should work.

sl1pkn07 commented 4 years ago

the last error i fixed with

        self.queue = queue.Queue()

(https://stackoverflow.com/a/54845594)

but i'm not coder. is all ok with my changes?

EDIT: oh. happy easter to you (in my country is "Saint Week" xd)

GiulianoSpaghetti commented 4 years ago

There is another Queue to fix,

import queue as Queue at line 12 an then self.queue=Queue.Queue();

and it works.

But mine is line 163, not 166

sl1pkn07 commented 4 years ago

i can push a PR (but i need craft it first)

the line self.queue = queue.Queue() is valid also for python2? or need more workground

GiulianoSpaghetti commented 4 years ago

No. In python2 it's only "queue". I think that for getting the code universal you should see if the python interpreter is 2 or 3 and give him the correct line.

GiulianoSpaghetti commented 4 years ago

For the PR, wait the accomplishment of the master.