matthewwall / weewx-sftp

report generator that uploads files using sftp
GNU General Public License v3.0
13 stars 3 forks source link

Potential Python 3 error #9

Closed Brezentrager closed 4 years ago

Brezentrager commented 4 years ago

Hi Matthew, after updating weewx to version 4.0 (python 3), the SFTP extension crashes with the following error:

pi@raspberrypi:~ $ sudo wee_reports

Using configuration file /etc/weewx/weewx.conf

Generating for all time

Traceback (most recent call last):

  File "/usr/share/weewx/weewx/reportengine.py", line 180, in run

    obj = weeutil.weeutil.get_object(generator)(

  File "/usr/share/weewx/weeutil/weeutil.py", line 1093, in get_object

    mod = __import__(module)

  File "/usr/share/weewx/user/sftp.py", line 81

    except pysftp.ConnectionException, e:

                                     ^

SyntaxError: invalid syntax

This error has to do with the '#sftp.last' file in usr/www/html/weewx.

I've then deleted the #sftp.last file. The weewx reporting engine then doesn't crash anymore, but produces the following warning:

pi@raspberrypi:~ $ sudo wee_reports

Using configuration file /etc/weewx/weewx.conf

Generating for all time

Traceback (most recent call last):

  File "/usr/share/weewx/weewx/reportengine.py", line 197, in run

    obj.start()

  File "/usr/share/weewx/weewx/reportengine.py", line 280, in start

    self.run()

  File "/usr/share/weewx/user/sftp.py", line 259, in run

    n = uploader.run()

  File "/usr/share/weewx/user/sftp.py", line 89, in run

    (timestamp, fileset) = self.get_last_upload()

  File "/usr/share/weewx/user/sftp.py", line 158, in get_last_upload

    timestamp = cPickle.load(f)

TypeError: a bytes-like object is required, not 'str'

Please note: Since my workaround at least fixed the crash, this issue is not priority 1

Best regards, Manfred

Brezentrager commented 4 years ago

I've tried some fixes and ended up with a version that seems to work. (Disclaimer: I don't know much about python coding)

1) Replaced "cPickle" by "pickle" 2) line 157 changed to: with open(tsfile, "rb") as f: 3) line 173 changed to: with open(tsfile, "wb") as f:

As mentioned, I'm not at all into python. So there will be a much better fix. And in fact I'm not even sure whether my issue with the current version is a general one, since you mention in your commit messages that the extension will work with weewx 4.0 and Python 3.

matthewwall commented 4 years ago

thank you for pointing this out, and your fix is correct.

please try sftp 0.7 (commit 0d02ecd)