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 support: fix errors related to byte/string conversion #30

Closed
wants to merge 1 commit into from

Conversation

ec1oud
Copy link

@ec1oud ec1oud commented Jan 1, 2019

There were a lot of errors like "a bytes-like object is required,
not 'str'" and the opposite error.

https://stackoverflow.com/questions/33054527/python-3-5-typeerror-a-bytes-like-object-is-required-not-str-when-writing-t
points out that if you open a file in binary mode, you need to write
bytes, not text. It turns out that Popen with universal_newlines
will open the pipe in text mode rather than binary mode; whereas the
regular file opening calls here are already in text mode, so converting
to utf-8 is not required when writing strings (I hope that means
Python already does that by default).

There were a lot of errors like "a bytes-like object is required,
not 'str'" and the opposite error.

https://stackoverflow.com/questions/33054527/python-3-5-typeerror-a-bytes-like-object-is-required-not-str-when-writing-t
points out that if you open a file in binary mode, you need to write
bytes, not text.  It turns out that Popen with universal_newlines
will open the pipe in text mode rather than binary mode; whereas the
regular file opening calls here are already in text mode, so converting
to utf-8 is not required when writing strings (I hope that means
Python already does that by default).
@ec1oud
Copy link
Author

ec1oud commented Jan 1, 2019

I'm not normally much of a python user (so far) so this is guesswork for me, but it seems to work now. I have version 3.7.1 FWIW.

@peterjc
Copy link
Owner

peterjc commented Jan 2, 2019

This was all written and tested under Python 2, and has not been tested under Python 3.

@peterjc
Copy link
Owner

peterjc commented Jan 2, 2019

Cross reference #24

@milahu
Copy link

milahu commented Jul 1, 2023

also replace title.encode("utf-8") with title etc,
otherwise strings are formatted as binary strings (b'...') in the output files.

@peterjc peterjc changed the title fix errors related to byte/string conversion python 3 support: fix errors related to byte/string conversion Jul 1, 2023
@peterjc peterjc mentioned this pull request Jan 12, 2024
@peterjc
Copy link
Owner

peterjc commented Jan 15, 2024

Thank you for looking at this - I did something similar for what is now v1.1.0:

https://github.com/peterjc/mediawiki_to_git_md/tree/v1.1.0

@peterjc peterjc closed this Jan 15, 2024
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.

None yet

3 participants