Skip to content

Conversation

DoctorOctagonapus
Copy link

Write result as string not bytes. Required for script to run under python3.

Without this change, script will return the following error: Traceback (most recent call last):
File "getBroadlinkSharedData.py", line 121, in
codesFile.write(result.encode('utf-8'))
TypeError: write() argument must be str, not bytes

Write result as string not bytes. Required for script to run under python3.

Without this change, script will return the following error:
Traceback (most recent call last):
  File "getBroadlinkSharedData.py", line 121, in <module>
    codesFile.write(result.encode('utf-8'))
TypeError: write() argument must be str, not bytes
@clach04
Copy link
Owner

clach04 commented Sep 27, 2022

Thanks @DoctorOctagonapus for taking the time to make a fix/patch and share!

I'm more inclined to go the route of opening the file in binary mode to begin with and preserve the manual encoding call (alternative wrap using codecs interface). On platforms where the encoding is NOT set (for example Windows and some Linux distros on SBCs like the rock64), the proposed fix won't work (your point that it doesn't work-at-all as bytes is noted ;-) )

I.e.:

codesFile = open(accessory_name + '.txt', 'w')

would become:

codesFile = open(accessory_name + '.txt', 'wb')

would work for 2.x and 3.c

That being said, I've not used this code in ages, I only forked it to have a place where it worked for me so I don't have a real dog in this fight and whilst I'm confident in the change above I've not actually tested it (and due to other commitments can't dedicate the time).

@DoctorOctagonapus
Copy link
Author

Ah that's the one! I saw various posts talking about adding 'wb' to the open command but didn't spot that line while I was looking through. I'm no Python expert, I just mess around with other people's code to try and make it work for my use case! You're right your fix would probably be better; my fix worked for me but probably because I'm on a Mac rather than Windows.

Yeah scripts like this are the kind of thing you would only use once in an ideal world. Only reason I needed to use it is all but one of my TC2s reset themselves and I needed the new code strings.

clach04 added a commit that referenced this pull request Sep 28, 2022
@clach04
Copy link
Owner

clach04 commented Sep 28, 2022

Cool. I went ahead and made an 100% untested change against the py3 branch (that way upstream an pick this up in the old PR NightRang3r#25 from 2018), then merged over to my main.

I'll close this. Again, thanks for the heads up, even though untested based on your observation we need it :-)

@clach04 clach04 closed this Sep 28, 2022
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

Successfully merging this pull request may close these issues.

2 participants