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

Python 3 #134

Open
eddiek2000 opened this issue Sep 3, 2022 · 19 comments
Open

Python 3 #134

eddiek2000 opened this issue Sep 3, 2022 · 19 comments

Comments

@eddiek2000
Copy link

Anyone done any work porting this project to python3? I tried and updated a few things, but am not getting far.

@commputethis
Copy link

commputethis commented Sep 4, 2022

I tried, but never could get it to work. So I found another way using MQTT and Home Assistant based on https://renjithn.com/garagepi-garage-opener-using-raspberry-pi/. I found this tutorial to not be quite right, so I added some documentation about what I did to get it to work.

https://commputethis.github.io/MQTT-GaragePi/

@eddiek2000
Copy link
Author

Thanks. I am still going to keep trying at the Python3 conversion. I have used this app for years and really like it. I have ZERO python/twisted/web experience, but am half way through a python course. With that being said, I have just been able to get the doors and uptime to be displayed on the webpage. Damn strings and byte strings/Python2/3. Not sure if what I have coded is good, but seems to work. Now I am working on the opening/closing/push control. There is some difference between P2 and P3 with 'door = request.args['id'][0]' , but I'll figure to out.

I have a Buster install and a Bullseye install and am comparing the handling of messages/variables. Hoping to have another breakthrough soon. Found that http://garagepiserver/cfg and http://garagepiserver/upt were good debugging sources for passed messages.

@eddiek2000
Copy link
Author

Got it working with Python3 and python3-twisted. Haven't tested anything other than the webpage being displayed correctly and the doors opening and closing and being displayed properly. I don't use authentication or any of the alerts. If anyone wants a copy, let me know.

@Gilles94500
Copy link

Hi Eddiek2000,
My rpi2 has burnt, so I try to install the garage-door-controller on a rpi3B. Now, only python3 is available. I have used the 2to3 script to migrate to python3, then corrected some errors with zope.interface , then with PutChild statements. Now I have no more errors in the logs, but the webpage remains empty except the html header. I have tried to use the chrome inspect tool and it seems that there may be an issue with JS.
Any idea ? Did I miss somùething ? You mention bove that it has worked for you without any security.
Thanks
Gilles

@Gilles94500
Copy link

I give up and will try to rewrite it with flask instead of twisted.

@eddiek2000
Copy link
Author

eddiek2000 commented Feb 13, 2023 via email

@Gilles94500
Copy link

Gilles94500 commented Feb 13, 2023 via email

@eddiek2000
Copy link
Author

eddiek2000 commented Feb 13, 2023

As promised, my version:

garage-door-controller.tar.gz

Also needed is python3-twisted. Might need some other packages, but they should be evident.

@Gilles94500
Copy link

Thanks a lot.

@Gilles94500
Copy link

Hi Eddy,
I have amended my version with your python3 and twisted updates. The main status page is shown, but it is impossible to authenticate to open or close a door. I am using the command : https://userid:[email protected]:8889/ .
I am asked for a user/password ( it is already in the https command) nd there is no way to authenticate.
Authentication is the main concern. I don't want anybody to be able to open my garage doors without authenticating :).

I will try to write the same appli in python and Flask, but it is a lot to learn for a newbie...

Thanks anyway
Gilles

@eddiek2000
Copy link
Author

As I stated before, I don't have a cert for https or use auth, but I did find a bad line at Line 321. I left out a b before clk. The line should be:
root.putChild(b'clk', protected_resource)

This brings up the username password prompt, but they aren't accepted. It is probably due to the way twisted is sending the user/pass back to python for authentication. Python2/3 handle strings differently. I am by no means programmer, but will try to look into this when I have a little free time.

@Gilles94500
Copy link

I had already added the missing 'b' in the version I am working on.I have already worked on the migration. and found some (encode utf-8) to add . There is also a "//" to use instead of a "/" in (elapsed_time: value = seconds // length)
No way to make it work.
The way to migrate from twisted2 to twisted3 is described on the twisted site but they only talk abour the @Implementer.
I have not found an example which could be reusable in the controller.py. :(

@Gilles94500
Copy link

I found the error that I did with the twisted authentication.
The password has to be in Byte with python3.
args={self.config['site']['username']:self.config['site']['password']}
A way to do it is : string = bytes(string, encoding= 'utf-8')
You also need to encode the "ok" answer in the render with : return "ok".encode('utf-8')

Now it works fine with my test raspberry which has no cabling yet.

@eddiek2000
Copy link
Author

eddiek2000 commented Feb 15, 2023 via email

@NCAvian
Copy link

NCAvian commented Nov 22, 2023

I found the error that I did with the twisted authentication. The password has to be in Byte with python3. args={self.config['site']['username']:self.config['site']['password']} A way to do it is : string = bytes(string, encoding= 'utf-8') You also need to encode the "ok" answer in the render with : return "ok".encode('utf-8')

Now it works fine with my test raspberry which has no cabling yet.

Gilles, how did you fix these? Could you post the code?

@Gilles94500
Copy link

Gilles94500 commented Nov 22, 2023 via email

@NCAvian
Copy link

NCAvian commented Nov 22, 2023

Thanks, Gilles! Everything seems to work except for authentication and SSL, although I haven't dug deeply into them yet. I've been tinkering with my code that puts the open/close times into the web page. With the latest version of Raspbian, they're now using journalctl instead of the log files. Cheers!

@andrewshilliday
Copy link
Owner

Andrew doesn’t answer anymore ☹ Thanks to him anyway

I'm sorry I haven't been responsive. I don't really use the device anymore so I haven't been keeping up with this project. If anyone else would like to officially take it over, I'd be happy to figure out how to transfer it. And maybe if I get some time this week I'll work on updating the code. It's been quite some time.

@Gilles94500
Copy link

Gilles94500 commented Nov 27, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants